我已经编写了这段代码以在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);}
}
}
最佳答案
问题是您在INTO
关键字中有空格,
insert in to xmltable values(?,?)
^ causes the error
它应该是
insert into xmltable values(?,?)