String str = "insert into table2 values(?,?,?,?,?,?)";
Class.forName("com.hxtt.sql.access.AccessDriver").newInstance();
String dbur1 = "jdbc:Access:///d://a1.mdb";
Connection conn = DriverManager.getConnection(dbur1,"Admin","000");

//Statement stmt = conn.createStatement();
PreparedStatement stmt = conn.prepareStatement(str);
stmt.setString(1,"史诗");
        stmt.setString(2,"Hello");
        stmt.setString(3,"dto");
        stmt.setInt(4,700);
        stmt.setInt(5,70);
        stmt.setInt(6,7);
try{
//stmt.executeUpdate("insert into table2 values('goiy','kk','kk',7,6,8)");
stmt.executeUpdate();//总报错
}catch (Exception e) {
e.printStackTrace();
}

解决方案 »

  1.   

    stmt.executeUpdate();
    不用传值么?
      

  2.   

    stmt.executeUpdate();的上面注释的那一行我用的传值,但还是不行,这两种情况都报错,空指针异常。
    java.sql.SQLException: java.lang.NullPointerException
    at com.hxtt.sql.access.aw.dc(Unknown Source)
    at com.hxtt.sql.access.bc.a(Unknown Source)
    at com.hxtt.sql.x.a(Unknown Source)
    at com.hxtt.sql.b6.for(Unknown Source)
    at com.hxtt.sql.b0.int(Unknown Source)
    at com.hxtt.sql.dn.a(Unknown Source)
    at com.hxtt.sql.bs.a(Unknown Source)
    at com.hxtt.sql.aj.a(Unknown Source)
    at com.hxtt.sql.dq.else(Unknown Source)
    at com.hxtt.sql.dq.executeUpdate(Unknown Source)
    at hh.kk.main(kk.java:33) at com.hxtt.global.SQLState.SQLException(Unknown Source)
    at com.hxtt.sql.bs.a(Unknown Source)
    at com.hxtt.sql.aj.a(Unknown Source)
    at com.hxtt.sql.dq.else(Unknown Source)
    at com.hxtt.sql.dq.executeUpdate(Unknown Source)
    at hh.kk.main(kk.java:33)
    33行就是我标出错的那一行
      

  3.   

    你用preparestatement  SQL语句应该这么写吧:insert into table2 values(?,?,?,?,?,?)
      

  4.   

    jdbc吗,网上一大堆,你搜个基础教程重新照着做,还有数据库mysql和oracle数据库连接是不一样的,不百度看看,最详细
      

  5.   

    Access数据库  JDK (不是1.8)自带驱动了啊,可以改那个试试
    32位系统:jdbc:odbc:Driver={MicroSoft Access Driver (*.mdb)};DBQ=
    64位系统 :jdbc:odbc:DRIVER=Microsoft Access Driver (*.mdb, *.accdb);DBQ=
      

  6.   

    a1.mdb 有没有写权限