I'm trying to insert data to MySQL table, but i got exception message which say:
Apr 16, 2012 3:01:03 PM RFID.RFID passDetInput
SEVERE: Can not issue data manipulation statements with executeQuery().
java.sql.SQLException: Can not issue data manipulation statements with executeQuery().
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1075)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:989)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:984)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:929)
at com.mysql.jdbc.StatementImpl.checkForDml(StatementImpl.java:436)
at com.mysql.jdbc.StatementImpl.executeQuery(StatementImpl.java:1390)
at RFID.RFID.passDetInput(RFID.java:495)
at RFID.RFID.SaveActionPerformed(RFID.java:472)
at RFID.RFID.access$700(RFID.java:28)
at RFID.RFID$7.actionPerformed(RFID.java:259)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2018)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2341)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:252)
at java.awt.Component.processMouseEvent(Component.java:6504)
...
This is my code to do the data manipulation:
import java.sql.*;
import java.util.logging.Level;
import java.util.logging.Logger;
public void passDetInput(String tag, String fname, String lname, String pID, String ConNo, String phone) {
String SQLcomm = "insert into pass_det (RFID_tag, fname, lname, ID_num, Conveyor_num, Phone_num) values (/'"+tag+"/',/'"+fname+"/',/'"+lname+"/',/'"+pID+"/',/'"+ConNo+"/',/'"+phone+"/')";
java.sql.Connection con = null;
Statement st = null;
ResultSet rs = null;
String url = "jdbc:mysql://localhost:3306/passenger_details";
String user = "root";
String password = "";
try {
con = DriverManager.getConnection(url, user, password);
st = con.createStatement();
rs = st.executeQuery(SQLcomm);
} catch (SQLException ex) {
Logger lgr = Logger.getLogger(RFID.class.getName());
lgr.log(Level.SEVERE, ex.getMessage(), ex);
}
}
and the function is executed via button-press.
I've check the database name, table name, and elements name, and they're all correct. Where's the mistake in my code?
Thank's in advance.
executeQuery()" means that you can not use data manipulation statements such asINSERT,UPDATEandDELETEwithexecuteQuery(). You must use them withexecuteUpdate()andexecuteQuery()with aSELECTstatement.