gpt4 book ai didi

java - 为什么我收到错误语法错误?

转载 作者:太空宇宙 更新时间:2023-11-03 12:08:00 25 4
gpt4 key购买 nike

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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com