标题:mysql插入数据出错
取消只看楼主
列车永不停息
Rank: 2
等 级:论坛游民
帖 子:76
专家分:48
注 册:2015-7-31
结帖率:90.91%
已结贴  问题点数:20 回复次数:1 
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)
搜索更多相关主题的帖子: 数据库 password mysql 1230 
2015-12-22 17:12
列车永不停息
Rank: 2
等 级:论坛游民
帖 子:76
专家分:48
注 册:2015-7-31
得分:0 
回复 2楼 紫月一殇雪
没有用呀?我移到Statement之前没用,移到Connection也没有用呀
2015-12-22 21:14



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-460469-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.425549 second(s), 10 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved