gpt4 book ai didi

mysql - com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException : You have an error in your SQL syntax;

转载 作者:行者123 更新时间:2023-11-30 22:18:18 24 4
gpt4 key购买 nike

嘿伙计们,我有这个错误消息,我在服务器和客户端之间连接,从 mysql 服务器选择数据并将其插入 mysql 客户端,但插入语句没有发生

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 ''context'.login VALUES (1,'Alamal','alamal','alamal','alamal)' at line 1

这是代码..

<%
try{
Connection con1;
Connection con2;
Class.forName("com.mysql.jdbc.Driver");
con1=(Connection)DriverManager.getConnection("jdbc:mysql://192.168.101.1:3306/context","hospital","0000");
PreparedStatement ps1=(PreparedStatement)con1.prepareStatement("SELECT * from hospital");
String str;
ResultSet rs1=ps1.executeQuery();

while(rs1.next()){
con2=(Connection)DriverManager.getConnection("jdbc:mysql://localhost:3306/context","root","");
con2.setAutoCommit(true);
con2.createStatement();
int id=rs1.getInt("ID");
String username=rs1.getString("UserName");
String password=rs1.getString("Password");
String hname=rs1.getString("HospitalName");
String haddress=rs1.getString("HospitalAddress");
PreparedStatement state= (PreparedStatement)con2.prepareStatement("INSERT INTO 'context'.'login' VALUES(?,?,?,?,?);");
state.setInt(1, id);
state.setString(2, username);
state.setString(3, password);
state.setString(4, hname);
state.setString(5, haddress);
state.executeUpdate();
con2.close();
}
con1.close();

} catch(Exception ex){
out.print(ex);
}
%>

最佳答案

您在编写 SQL 查询时犯了愚蠢的错误,现在它可以正常工作了。

<%
try{
Connection con1;
Connection con2;
Class.forName("com.mysql.jdbc.Driver");
con1=(Connection)DriverManager.getConnection("jdbc:mysql://192.168.101.1:3306/context","hospital","0000");
PreparedStatement ps1=(PreparedStatement)con1.prepareStatement("SELECT * from hospital");
String str;
ResultSet rs1=ps1.executeQuery();

while(rs1.next()){
con2=(Connection)DriverManager.getConnection("jdbc:mysql://localhost:3306/context","root","");
con2.setAutoCommit(true);
con2.createStatement();
int id=rs1.getInt("ID");
String username=rs1.getString("UserName");
String password=rs1.getString("Password");
String hname=rs1.getString("HospitalName");
String haddress=rs1.getString("HospitalAddress");
PreparedStatement state= (PreparedStatement)con2.prepareStatement("INSERT INTO `context`.`login` VALUES(?,?,?,?,?);");
state.setInt(1, id);
state.setString(2, username);
state.setString(3, password);
state.setString(4, hname);
state.setString(5, haddress);
state.executeUpdate();
con2.close();
}
con1.close();

} catch(Exception ex){
out.print(ex);
}
%>

关于mysql - com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException : You have an error in your SQL syntax;,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37498176/

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