Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
245 views
in Technique[技术] by (71.8m points)

JDBC SQLException

public static void add(String username_, String password)
{
   try {
       conn = DBConnection.getConnection();
       String sql = "insert into userinfo (uid, user, password) values (null,'?','?')";
        pstm = conn.prepareStatement(sql);
        pstm.setString(2,username_);
        pstm.setString(3,password);
        pstm.executeUpdate();
        System.out.println("数据添加成功");
     }catch (SQLException e) {
            e.printStackTrace();
     }
   }
}
        pstm.setString(2,username_);
        pstm.setString(3,password);

``
java.sql.SQLException: Parameter index out of range (2 > number of parameters, which is 0).

为什么错?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

?号那里的单引号去掉试试


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...