本文介绍了参数索引超出范围(1>参数个数,为0)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
参数索引超出范围(1>参数个数,为0)
我尝试过:
这是我的代码。表用户包含3行。有用户名和密码。它给我的错误如下:
Parameter index out of range(1> number of parameters,which is 0)
What I have tried:
This is my code.The table users contains 3 rows.having username and password.It is giving me the error as:
java.sql.SQLException: Parameter index out of range (1 > number of parameters, which is 0).
String DRIVER = "com.mysql.jdbc.Driver";
Class.forName(DRIVER).newInstance();
String url="jdbc:mysql://localhost:3306/regis?user=root&password=fraze";
Connection Conn = DriverManager.getConnection(url);
String strSQL = "select username,password from users where username like '%s';
PreparedStatement statement = Conn.prepareStatement(strSQL);
statement.setString(1, user);
statement.setString(2, pass);
ResultSet Rs= statement.executeQuery(strSQL);
if(myRs.next()){
out.println("Login Succesful! A record with the given user name and password exists");
} else {
out.println("Login Failed. No records exists with the given user name and password");
}
statement.close();
我想要如果输入的用户名和密码是否正确,请与数据库进行核实。任何人都可以建议做出适当的更改。
I want to verify with the database if the username and password entered are correct or not. Could any one suggest as what would be appropriate changes that are to be made.
推荐答案
这篇关于参数索引超出范围(1>参数个数,为0)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!