数据库操作中,如何替换系统容错提示?
用ADO进行数据库查询、更新或删除。如果列值有错误,就会直接弹出系统的错误(一串英文),可是如何通过程序来把这些错误提示截获,并且改成自定义的提示呢?
例如:
1、插入值类型错误
2、插入值不能为NULL
3、插入字符串过长
4、连接数据库超时(无法连接数据库)
……
请大侠们先协助解决一下上述4个例子,当然如果您那里有更多的提示说明就更好了。~先谢了
[解决办法]
try
{
XXX;
}
catch(Exception &e)
{
ShowMessage(e.Message);//出错消息
}
[解决办法]
接管Application的OnException事件,做一个窗口模板,用来显示异常的信息。
[解决办法]
try { // Execute SQL statements...} catch (SQLException e) { while (e != null) { // Retrieve a human-readable message identifying the reason for the exception String message = e.getMessage(); // This vendor-independent string contains a code that identifies // the reason for the exception. // The code follows the Open Group SQL conventions. String sqlState = e.getSQLState(); // Retrieve a vendor-specific code identifying the reason for the exception. int errorCode = e.getErrorCode(); // If it is necessary to execute code based on this error code, // you should ensure that the expected driver is being // used before using the error code. // Get driver name String driverName = connection.getMetaData().getDriverName(); if (driverName.equals("Oracle JDBC Driver") && errorCode == 123) { // Process error... } // The exception may have been chained; process the next chained exception e = e.getNextException(); }}