2013-05-06 2 views
0

자바 프로그램을 사용하여 값을 내 SQL 삽입, 나는 이미 데이터베이스 연결 을 한이 오류가 점점 오전 : com.mysql.jdbc.exceptions.MySQLSyntaxErrorException내가 MySQL의에서 값을 삽입하는 코드를 작성했습니다

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);} 
     } 
} 
+1

'into'가 아니라 'in to' – Maroun

답변

4

문제가 당신이 공간이입니다 INTO 키워드에,

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

그것은해야

insert into xmltable values(?,?) 
+0

이제 오류가 발생합니다 : -com.mysql.jdbc.exceptions.MySQLIntegrityConstraintViolationException : 키 'PRIMARY'에 대한 항목 '101'이 복제 됨 –

+0

그것은 이미 값이 있음을 의미합니다. 존재하는 기본 키. 자동 증분 열이 있습니까? –

+0

예 자동 증분 열 ID가 있습니다. –

관련 문제