往Access往数据库中插入数据如
stmt.executeUpdate("insert into table_1  values('userName','userPass')");总提示错误是什么原因啊?
提示的错误是查询值的数目和目标字段中的值不同。
再说一下userName和userPass分别是从图形用户界面上的文本框和密码框中获取的作为参数传到这里的。数据库中该字段的属性都是文本型。

解决方案 »

  1.   

    1、你的table_1的表结构是什么啊 ,是不是只有两列并且两列是文本类型的啊 ?2、如果只有两列,而且都是文本的话,这个stmt.executeUpdate("insert into table_1 values('userName','userPass')"); 应该插入一条数据,数据为userName 和 userPass的记录啊 ,你是写死的啊 ,
    PreparedStatement  perstmt ;   
    perstmt = con.prepareStatement("insert into table_1 (userName,userPass) values (?,?)");    
    perstmt.setString(1,userName);    
    perstmt.setString(2,userPass);    
        
    perstmt.executeUpdate();  
      

  2.   


    //这样也可以  如果不用预编译
    stmt.executeUpdate("insert into table_1 values('" + userName + "','" + userPass + "')");
      

  3.   

    Access数据库的表中有一列是ID列是自动生成的会不会是因为它有影响啊?我把这段程序附上请高手找一下毛病。
    String b(String userName, String userPass){
            String str="";
            try{Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");}
            catch(ClassNotFoundException e){System.out.println(""+e);
            }
         try{conn = DriverManager.getConnection("jdbc:odbc:ljd","","");
           
            stmt = conn.createStatement();
            //stmt.executeUpdate("insert into table_1  values('userName','userPass')");
            stmt.executeUpdate("insert into table_1 values('" + userName + "','" + userPass + "')");
            rs=stmt.executeQuery("select * from table_1 where s_name=userName");
            while(rs.next()){ String name=rs.getString(1);
                              String pw=rs.getString(2);
                               str="用户名:"+name+","+"密码:"+pw;
            }
            }
            catch(SQLException e){System.out.println(e);}
            finally{ 
            try{
                    if(rs != null){rs.close();}
                if(stmt != null){stmt.close();}
                    if(conn != null){conn.close();}
                   }
                    catch (Exception e){ e.printStackTrace(); }
            }
            return str;
           }
      

  4.   

    估计是LZ的表不止这两个字段,在table_1后面跟上要加字段的名字