[英]My SQL insertion of values using java program
I have written this code to insert values in mysql ,I have already made database connection I am getting this error: com.mysql.jdbc.exceptions.MySQLSyntaxErrorException
我已编写此代码在mysql中插入值,已经建立数据库连接,我收到此错误:
com.mysql.jdbc.exceptions.MySQLSyntaxErrorException
public class JavaMysql {
public static void main(String[] args) {
String url = "jdbc:mysql://localhost:3306/bhuwan";
String driver = "com.mysql.jdbc.Driver";
String userName = "root";
String password = "rpass";
try {
Class.forName(driver).newInstance();
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/bhuwan","root","rpass");
PreparedStatement stmt=conn.prepareStatement("insert in to xmltable values(?,?)");
stmt.setInt(1,101);
stmt.setString(2,"Nitish Sharma");
stmt.execute();
int i=stmt.executeUpdate();
System.out.println(i+"records inserted");
conn.close();
}catch(Exception e){System.out.println(e);}
}
}
the problem is you have a space in INTO
keyword, 问题是
INTO
关键字中有空格,
insert in to xmltable values(?,?)
^ causes the error
it should be 它应该是
insert into xmltable values(?,?)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.