0

I have written this code to insert values in mysql ,I have already made database connection I am getting this error: 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);}
         }
}
1
  • 1
    into and not in to Commented May 6, 2013 at 6:54

1 Answer 1

4

the problem is you have a space in INTO keyword,

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

it should be

insert into xmltable values(?,?)
Sign up to request clarification or add additional context in comments.

2 Comments

now i am getting a error:-com.mysql.jdbc.exceptions.MySQLIntegrityConstraintViolationException: Duplicate entry '101' for key 'PRIMARY'
it just means there is already a value for the primary key the exists. do you have any auto increment column?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.