我正在尝试将数据插入 MySQL 表,但我收到异常消息:
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)
...
这是我进行数据操作的代码:
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);
}
}
该功能通过按键执行。
我检查了数据库名称、表名称和元素名称,它们都是正确的。我的代码中的错误在哪里?
提前致谢。