把运行结果都列出来才好找错特别是这几句的运行结果。你table设置时可以重复输入相同行吗? if (ds != null) {
Connection conn = ds.getConnection();
if(conn != null) {
foo = "Got Connection "+conn.toString();
Statement stmt = conn.createStatement();
String insert="insert into testdata values(null, 'good boy', 12345)";
stmt.executeUpdate(insert);
rst =
stmt.executeQuery(
"select * from testdata ");
//这句话运行完,能不能把结果打印出来?
conn.close();
}
Connection conn = ds.getConnection();
if(conn != null) {
foo = "Got Connection "+conn.toString();
Statement stmt = conn.createStatement();
String insert="insert into testdata values(null, 'good boy', 12345)";
stmt.executeUpdate(insert);
rst =
stmt.executeQuery(
"select * from testdata ");
//这句话运行完,能不能把结果打印出来?
conn.close();
}
String insert="insert into testdata values(null, 'good boy', 12345)";第一列是auto_increment,你把这句改成
String insert="insert into testdata values('good boy', 12345)";
试一试
这句话是绝对没有问题的,对于auto_increment类型的列,如果你显式地进行插入,如上所写,插入null,就可以;要不就干脆不写出来,也可以。