用的数据库就是access,数据库没有问题,我用Statement进行操作可以将数据插进去,但是用PreparedStatement就不行了,不知是何缘故?

解决方案 »

  1.   

    是的,忘记了加上 stm.executeUpdate();
      

  2.   

    是的,忘记了加上 stm.executeUpdate();
    是啊,怎么可以忘记加上insert execute呢?
      

  3.   

    忘记了加上 stm.executeUpdate();
      

  4.   

    stm.executeUpdate();
    没有这句根本就没有执行插入操作,怎么可能有数据呢!
      

  5.   


    import java.sql.*;
    public class test{
    public static void main(String args[])throws Exception{
        Connection con;
        try{
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    con=DriverManager.getConnection("jdbc:odbc:Test","","");
    PreparedStatement stm=con.prepareStatement("insert into myTable values(?,?)");
    stm.setInt(1,5);
    stm.setString(2,"hello");
                      smt.executeUpdate()//執行SQL
                    stm.close();
                    con.close();
           
       }
       catch(SQLException e){e.printStackTrace();}
    }
    }