Cannot insert into table using JDBC
The following query was successful when I used in mysql
INSERT INTO user(`dev_id`,`email`) VALUES('123','456@gmail.com');
But in java jdbc I got this exception:
Can not issue data manipulation statements with executeQuery().
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:910)
at com.mysql.jdbc.Statement.checkForDml(Statement.java:417)
at com.mysql.jdbc.Statement.executeQuery(Statement.java:1140)
My table has 5 columns and 3 columns has default = null;
+3
source to share
4 answers
You should use executeUpdate () instead of executeQuery () . JavaDoc:
Executes an SQL job, which can be an INSERT, UPDATE, or DELETE, or an SQL statement that returns nothing, such as SQL DDL.
Note. This method cannot be called on PreparedStatement or CallableStatement.
Parameters: sql - SQL Data Manipulation Language (DML) statement such as INSERT, UPDATE, or DELETE; or an SQL statement that returns nothing, such as a DDL statement.
Also, whenever a problem occurs - check the javadoc first and try googling. Stackoverflow is a bit delicate for your case.
+1
source to share