嘿家伙我有这个错误信息,我在服务器和客户端之间连接,从mysql服务器中选择数据并将其插入mysql客户端但插入语句不会发生
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException:您的SQL语法中有错误;查看与您的MySQL服务器版本相对应的手册,以获得正确的语法,以便在'' context' .login VALUES(1,' Alamal',' alamal&#)附近使用39;,' alamal'' alamal)'在第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);
}
%>
答案 0 :(得分:0)
你在编写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);
}
%>
答案 1 :(得分:0)
SQL中的引号(std::list<item*> items
)用于表示字符串文字,而不是对象名称。放下它们就可以了:
std::list