在jdbc中执行错误的sql语句时会抛出SQLException异常,但是却不知道异常的具体原因,能不能用异常对象的getSQLState()方法返回的字符串来区分产生异常的具体原因呢?比如:
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
} catch (ClassNotFoundException ex) {
}
try {
Connection con = DriverManager.getConnection("jdbc:odbc:test");
Statement st = con.createStatement();
st.executeUpdate(
"insert into student values('liu',23,null,124,'tian')");
st.close();
con.close();
} catch (SQLException ex1) {
if(ex1.getSQLState()=="23000"){
System.out.println("主键重复");
}
}
请高手指教
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
} catch (ClassNotFoundException ex) {
}
try {
Connection con = DriverManager.getConnection("jdbc:odbc:test");
Statement st = con.createStatement();
st.executeUpdate(
"insert into student values('liu',23,null,124,'tian')");
st.close();
con.close();
} catch (SQLException ex1) {
if(ex1.getSQLState()=="23000"){
System.out.println("主键重复");
}
}
请高手指教
解决方案 »
- type mismatch between indexed and non-indexed methods
- 请问如何catch出一个像windows错误弹出框这样的弹出框?
- JNA愁死我了
- 高手进!关于Exception in thread "main" java.lang.NullPointerException问题!急………………
- 如何方便的发布JAVA的WEB程序?
- 请问:在java程序中如何调用ultraEdit打开文本文件?
- 一个javascript 问题
- 主程序非要等子线程死亡才可以退出吗?
- 帮忙调试一个关于万年历的程序~~~~~~~~
- 曾经有人告诉我一个非常好的论坛,我给忘了,谁能告诉我
- 初学socket,,做可以GUI的通讯程序,,
- 哪位给说一下yield(),sleep()以及wait()的区别
我试了试,好像:23000对应的是“主键重复”,37000对应的是“数据类型不符”是这样吗?请高手指教
1021 HY000 Disk full (%s); waiting for someone to free some space . . .
1022 23000 Can't write; duplicate key in table '%s'
1027 HY000 '%s' is locked against change
1036 HY000 Table '%s' is read only
1048 23000 Column '%s' cannot be null
1062 23000 Duplicate entry '%s' for key %d
1099 HY000 Table '%s' was locked with a READ lock and can't be updated
1100 HY000 Table '%s' was not locked with LOCK TABLES
1104 42000 The SELECT would examine more than MAX_JOIN_SIZE rows; check your WHERE and use SET SQL_BIG_SELECTS=1 or SET SQL_MAX_JOIN_SIZE=# if the SELECT is okay
1106 42000 Incorrect parameters to procedure '%s'
1114 HY000 The table '%s' is full
1150 HY000 Delayed insert thread couldn't get requested lock for table %s
1165 HY000 INSERT DELAYED can't be used with table '%s' because it is locked with LOCK TABLES
1242 21000 Subquery returns more than 1 row
1263 22004 Column set to default value; NULL supplied to NOT NULL column '%s' at row %ld
1264 22003 Out of range value adjusted for column '%s' at row %ld
1265 1000 Data truncated for column '%s' at row %ld
1312 0A000 SELECT in a stored program must have INTO
1317 70100 Query execution was interrupted
1319 42000 Undefined CONDITION: %s
1325 24000 Cursor is already open
1326 24000 Cursor is not open
1328 HY000 Incorrect number of FETCH variables
1329 2000 No data to FETCH
1336 42000 USE is not allowed in a stored program
1337 42000 Variable or condition declaration after cursor or handler declaration
1338 42000 Cursor declaration after handler declaration
1339 20000 Case not found for CASE statement
1348 HY000 Column '%s' is not updatable
1357 HY000 Can't drop a %s from within another stored routine
1358 HY000 GOTO is not allowed in a stored program handler
1362 HY000 Updating of %s row is not allowed in %s trigger
1363 HY000 There is no %s row in %s trigger