Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/396.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
我的SQL使用java程序插入值_Java_Mysql - Fatal编程技术网

我的SQL使用java程序插入值

我的SQL使用java程序插入值,java,mysql,Java,Mysql,我写了这段代码来在mysql中插入值,我已经建立了数据库连接 我收到这个错误:com.mysql.jdbc.exceptions.MySQLSyntaxErrorException public class JavaMysql { public static void main(String[] args) { String url = "jdbc:mysql://localhost:3306/bhuwan"; String driver = "c

我写了这段代码来在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);}
         }
}

问题是你在
中有一个空格进入
关键字

insert in to xmltable values(?,?)  
         ^ causes the error
应该是

insert into xmltable values(?,?)

问题是你在
中有一个空格进入
关键字

insert in to xmltable values(?,?)  
         ^ causes the error
应该是

insert into xmltable values(?,?)

进入
而不是
进入
而不是
进入
而不是
进入
现在我得到一个错误:-com.mysql.jdbc.exceptions.MySQLIntegrityConstraintViolationException:key“PRIMARY”的重复条目“101”它只是意味着主键已经存在一个值。您有任何自动增量列吗?现在我得到一个错误:-com.mysql.jdbc.exceptions.MySQLIntegrityConstraintViolationException:键'PRIMARY'的重复条目'101'它只是意味着已经存在主键的值。有自动递增列吗?