我尝试添加一个保存按钮,它在Eclipse控制台中给出了这个错误
java.sql.SQLException: Column count doesn't match value count at row 1 at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1073) at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3597) at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3529) at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1990) at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2151) at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2619) at com.mysql.jdbc.StatementImpl.executeUpdate(StatementImpl.java:1698) at com.mysql.jdbc.StatementImpl.executeUpdate(StatementImpl.java:1617) at LOTest$2.actionPerformed(LOTest.java:73) at javax.swing.AbstractButton.fireActionPerformed(Unknown Source) at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source) at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source) at javax.swing.DefaultButtonModel.setPressed(Unknown Source) at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source) at java.awt.Component.processMouseEvent(Unknown Source) at javax.swing.JComponent.processMouseEvent(Unknown Source) at java.awt.Component.processEvent(Unknown Source) at java.awt.Container.processEvent(Unknown Source) at java.awt.Component.dispatchEventImpl(Unknown Source) at java.awt.Container.dispatchEventImpl(Unknown Source) at java.awt.Component.dispatchEvent(Unknown Source) at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source) at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source) at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source) at java.awt.Container.dispatchEventImpl(Unknown Source) at java.awt.Window.dispatchEventImpl(Unknown Source) at java.awt.Component.dispatchEvent(Unknown Source) at java.awt.EventQueue.dispatchEvent(Unknown Source) at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source) at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source) at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source) at java.awt.EventDispatchThread.pumpEvents(Unknown Source) at java.awt.EventDispatchThread.pumpEvents(Unknown Source) at java.awt.EventDispatchThread.run(Unknown Source)
btnUpdateS.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent msUpdate) {
try {
qstm.qDB.executeUpdate("insert into matsub (matsubid, matsubname) values
('"+ txMatSID.getText() + "' + ',' + '" + txMatSName.getText() + "');");
getContentPane().add(scrollPane);
MatSTable.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS);
MatSTable.setFillsViewportHeight(true);
getContentPane().repaint();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
如果有人可以分享这个问题,我会很感激,我自己在这个java中很新。
答案 0 :(得分:1)
您需要在关系语句中转义文字引号"
,如The Java Tutorials: Characters所示。您可以使用连接运算符+
来撰写语句,如The Java Tutorials: Strings所示。