posted 10 years ago
I am inserting data into MySQL database table named users using object of Prepared-statement but it gives me following error.
Same insert statement is executing fine in MySQL command prompt and by using Statement object.
-- output on console
insertUser statement => com.mysql.jdbc.JDBC4PreparedStatement@19aae6a: INSERT INTO users(user_id, users_name, password, role, user_status)VALUES('99999','','12','ADMINISTRATOR','Blocked');
SQLException occured. getErrorCode=> 1064
SQLException occured. getCause=> 42000
SQLException occured. getCause=> null
SQLException occured. getMessage=> 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 '?,?,?,?,?)' at line 1
Following is the structure of table and output after executing above query.
mysql> describe users;
+-------------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------------+-------------+------+-----+---------+-------+
| user_id | varchar(20) | NO | PRI | NULL | |
| users_name | varchar(45) | YES | | NULL | |
| password | varchar(20) | YES | | NULL | |
| role | varchar(20) | YES | | NULL | |
| user_status | varchar(20) | YES | MUL | NULL | |
+-------------+-------------+------+-----+---------+-------+
5 rows in set (0.07 sec)
mysql> INSERT INTO users(user_id, users_name, password, role, user_status)VALUES
('99999','','12','ADMINISTRATOR','Blocked');
Query OK, 1 row affected (0.09 sec)
mysql>
Kindly guide me to resolve the issue.
Best regards,
Muhammad Yasir