【发布时间】:2016-05-28 11:02:10
【问题描述】:
大家好,我有这个错误消息,我在服务器和客户端之间连接,从 mysql 服务器中选择数据并将其插入 mysql 客户端,但插入语句没有发生
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: 你的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,以在第 1 行的 ''context'.login VALUES (1,'Alamal','alamal','alamal','alamal)' 附近使用正确的语法
这是代码..
<%
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);
}
%>
【问题讨论】:
-
从
'context'.'login'中删除单引号会发生什么? -
出现这条信息 com.mysql.jdbc.exceptions.jdbc4MYSQLSyntaxErrorException: Table 'context.login' doesn't exist
-
然后让舒尔确实存在。