mysql插入数据出错
程序代码:
import java.sql.DriverManager; import java.sql.SQLException; import com.mysql.jdbc.Connection; import com.mysql.jdbc.Statement; public class 数据库{ private static String user = "root"; private static String password = "1230"; private static String driverClass = "com.mysql.jdbc.Driver"; private static String url = "jdbc:mysql:///x"; public static void main(String[] args) throws SQLException, Exception { wo(); } private static void wo() throws SQLException, Exception { // TODO 自动生成的方法存根 Connection con = (Connection) DriverManager.getConnection(url,user,password); Statement sql = (Statement) con.createStatement();//实例化对象 // String s = "NSERT INTO x2(id,PASSWORD) VALUES('liuyuyu',5)"; Class.forName(driverClass);//加载驱动的; System.out.println(con); sql.executeUpdate(s); con.close(); } }
报错
com.mysql.jdbc.JDBC4Connection@6193b845
Exception in thread "main" 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 'NSERT INTO x2(id,PASSWORD) VALUES('liuyuyu',5)' at line 1
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:406)
at com.mysql.jdbc.Util.getInstance(Util.java:381)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1030)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:956)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3515)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3447)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1951)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2101)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2548)
at com.mysql.jdbc.StatementImpl.executeUpdate(StatementImpl.java:1605)
at com.mysql.jdbc.StatementImpl.executeUpdate(StatementImpl.java:1524)
at 数据库.数据库.wo(数据库.java:31)
at 数据库.数据库.main(数据库.java:18)