0

i have written a code to insert data in data base its is

String sql="INSERT INTO check (name,pass,pno) VALUES (?,?,?)";
            PreparedStatement pstmt = conn.prepareStatement(sql);
            pstmt.setString(1, name);
            pstmt.setString(2, pass);
            pstmt.setInt(3, no1);
            pstmt.executeUpdate();

As i have avoided the sql injection and used preparedstatement i am still getting this error in my server log:

SEVERE:   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 'check (name,pass,pno) VALUES ('Nikhil Muskur','qwerty1',7898455)' at line 1

i double checked it as nothing is wrong with the syntax then what is the problem can anybody help

4

2 回答 2

3

check is a reserved word in MySQL: http://dev.mysql.com/doc/refman/5.5/en/reserved-words.html

Change your query to:

String sql="INSERT INTO `check` (`name`, `pass`, `pno`) VALUES (?,?,?)";

so MySQL understands you are actually accessing a table.

于 2014-08-02T08:26:13.723 回答
0

('Nikhil Muskur','qwerty1',7898455) : update query by ('Nikhil Muskur','qwerty1','7898455')

7898455 must be an string value.

于 2014-08-02T08:28:23.557 回答