2011-07-11 75 views
-1

顯示我嘗試添加一個保存按鈕,這讓我在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

相關的帖子在這裏:[www.java-forums.org:JTable中-重繪(http://www.java-forums.org/awt-swing/46305-jtable-repaint.html) –

+0

那個帖子是我這是後我發現我在這裏發佈有關錯誤「java.sql.SQLException:列數不匹配在第1行的值計數」錯誤的問題,其中我修復了SQL後,我發現重繪方法不工作預計,現在所有的工作正常,但是,謝謝 – Levian

回答

1

您需要在關係語句中轉義文字引號",如The Java Tutorials: Characters所示。您可以使用連接運算符+來組成您的語句,如The Java Tutorials: Strings中所示。

+0

謝謝,是的問題是在報價中...有時它是在該部分混淆,並使其更難以追蹤...是搞清楚這個錯誤信息是什麼意思 – Levian

+0

編譯器看到兩個屬性,但超過兩個值。對不起,我無法完全從上下文中解析它。 – trashgod

+0

沒關係......它已經解決了,實際上是在這裏發帖,因爲我不知道那個錯誤信息是什麼意思,但進一步的嘗試給了我一個關於這個問題的線索......至少我知道下次如果我得到同樣的錯誤,這意味着我必須更仔細地檢查我的SQL語句與所有報價。 – Levian