Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/hibernate","root","root");
String query1= "select * from registration where email= ? and password= ? ";
PreparedStatement ps = con.prepareStatement(query1);
ps.setString(1,email);
ps.setString(2,password);
ResultSet rs1= ps.executeQuery(query1);
rs1.next();
String s= rs1.getString("type");
out.println(s);
我遇到以下错误-
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your
SQL syntax; check the manual that corresponds to your MySQL server version for the
right syntax to use near '? and password= ?' at line 1
最佳答案
ps.executeQuery(query1)
必须改为
ps.executeQuery()
否则,您执行的不是带有绑定(bind)参数的准备好的查询,而是没有任何参数绑定(bind)的未准备的查询。
关于java - 为什么我收到错误语法错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25594944/