A
anron
Unregistered / Unconfirmed
GUEST, unregistred user!
我有个Access文件aa.mdb,其中有个表test,有两个字段,一个是id,自动加一,一个是name,字符型.运行到Statement.RETURN_GENERATED_KEYS这行就报错!
原码如下:
package temp1;
import java.sql.*;
public class Untitled3 {
public static void main(String[] args) {
try {
String strUrl = "sun.jdbc.odbc.JdbcOdbcDriver";
String strCon = "jdbcdbcriver={Microsoft Access Driver (*.mdb)};DBQ=d:/aa.mdb";
Class.forName(strUrl);
Connection cn = DriverManager.getConnection(strCon);
Statement st = cn.createStatement();
int rn = st.executeUpdate("insert into test (name) values ('anron')", Statement.RETURN_GENERATED_KEYS);
System.out.println("RecordCount: "
+ rn);
ResultSet rs = st.getGeneratedKeys();
if (rs.next())
System.out.println(rs.getInt("id");
} catch (Exception ex) {
System.out.println(ex.getMessage());
}
}
}
原码如下:
package temp1;
import java.sql.*;
public class Untitled3 {
public static void main(String[] args) {
try {
String strUrl = "sun.jdbc.odbc.JdbcOdbcDriver";
String strCon = "jdbcdbcriver={Microsoft Access Driver (*.mdb)};DBQ=d:/aa.mdb";
Class.forName(strUrl);
Connection cn = DriverManager.getConnection(strCon);
Statement st = cn.createStatement();
int rn = st.executeUpdate("insert into test (name) values ('anron')", Statement.RETURN_GENERATED_KEYS);
System.out.println("RecordCount: "
+ rn);
ResultSet rs = st.getGeneratedKeys();
if (rs.next())
System.out.println(rs.getInt("id");
} catch (Exception ex) {
System.out.println(ex.getMessage());
}
}
}