日日操夜夜添-日日操影院-日日草夜夜操-日日干干-精品一区二区三区波多野结衣-精品一区二区三区高清免费不卡

公告:魔扣目錄網為廣大站長提供免費收錄網站服務,提交前請做好本站友鏈:【 網站目錄:http://www.ylptlb.cn 】, 免友鏈快審服務(50元/站),

點擊這里在線咨詢客服
新站提交
  • 網站:51998
  • 待審:31
  • 小程序:12
  • 文章:1030137
  • 會員:747

本文介紹了在嘗試將java NetBeans j表注冊表的數據放入mysql時,我不斷收到錯誤。的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我正在用Java NetBeans制作注冊表。我使用的是CRUD、jframe和jtable函數。我還需要實現MySQL查詢來將數據保存在MySQL工作臺中。但是每當我運行項目時,都會出現同樣的錯誤,程序提示MySQL語法錯誤。

  private void JB2ActionPerformed(java.awt.event.ActionEvent evt) {                                    
        // TODO add code here:
        
        try
        {
              Class.forName("com.mysql.cj.jdbc.Driver");
              sqlConn = DriverManager.getConnection(data,user,password);
              pst = sqlConn.prepareStatement("insert * into tracking_register_db(Name,Surname,Phone,Age,Adress,Email,"
                      + "Temp,Symptoms,Exsposed) value(?,?,?,?,?,?,?,?,?,)");
              
              pst.setString(1, JT1.getText());
              pst.setString(2, JT2.getText());
              pst.setString(3, JT3.getText());
              pst.setString(4, JT4.getText());
              pst.setString(5, JT5.getText());
              pst.setString(6, JT6.getText());
              pst.setString(7, JT7.getText());
              pst.setString(8, JT8.getText());
              pst.setString(9, JT9.getText());
              
              
              pst.executeUpdate();
              JOptionPane.showMessageDialog(this,"Record added");
              upDateDB();
              
              
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(Registration.class.getName()).log(Level.SEVERE, null, ex);
        } catch (SQLException ex) { 
            java.util.logging.Logger.getLogger(Registration.class.getName()).log(Level.SEVERE, null, ex);
        } 
                                    

這是我收到的錯誤:

java.sql.SQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '* into tracking_register_db(Name,Surname,Phone,Age,Adress,Email,Temp,Symptoms,Ex' at line 1
    at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:120)
    at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:122)
    at com.mysql.cj.jdbc.ClientPreparedStatement.executeInternal(ClientPreparedStatement.java:953)
    at com.mysql.cj.jdbc.ClientPreparedStatement.executeUpdateInternal(ClientPreparedStatement.java:1098)
    at com.mysql.cj.jdbc.ClientPreparedStatement.executeUpdateInternal(ClientPreparedStatement.java:1046)
    at com.mysql.cj.jdbc.ClientPreparedStatement.executeLargeUpdate(ClientPreparedStatement.java:1371)
    at com.mysql.cj.jdbc.ClientPreparedStatement.executeUpdate(ClientPreparedStatement.java:1031)
    at Registration.JB2ActionPerformed(Registration.java:462)
    at Registration.access$1000(Registration.java:28)
    at Registration$11.actionPerformed(Registration.java:302)
    at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2022)
    at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2348)
    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:6539)
    at javax.swing.JComponent.processMouseEvent(JComponent.java:3324)
    at java.awt.Component.processEvent(Component.java:6304)
    at java.awt.Container.processEvent(Container.java:2239)
    at java.awt.Component.dispatchEventImpl(Component.java:4889)
    at java.awt.Container.dispatchEventImpl(Container.java:2297)
    at java.awt.Component.dispatchEvent(Component.java:4711)
    at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4904)
    at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4535)
    at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4476)
    at java.awt.Container.dispatchEventImpl(Container.java:2283)
    at java.awt.Window.dispatchEventImpl(Window.java:2746)
    at java.awt.Component.dispatchEvent(Component.java:4711)
    at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:760)
    at java.awt.EventQueue.access$500(EventQueue.java:97)
    at java.awt.EventQueue$3.run(EventQueue.java:709)
    at java.awt.EventQueue$3.run(EventQueue.java:703)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:74)
    at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:84)
    at java.awt.EventQueue$4.run(EventQueue.java:733)
    at java.awt.EventQueue$4.run(EventQueue.java:731)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:74)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:730)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:205)
    at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)

推薦答案

尤其是準備好的語句不應聲明為字段。

使用try-with-resources自動關閉連接、語句和結果集(如果有)。即使在出現異常或返回的情況下也是如此。

    String sql = "insert into tracking_register_db(Name,Surname,Phone,Age,Adress,Email,"
                  + "Temp,Symptoms,Exsposed) values(?,?,?,?,?,?,?,?,?)"
    try {
        Class.forName("com.mysql.cj.jdbc.Driver");
        try (Connection sqlConn = DriverManager.getConnection(data, user, password);
                  PreparedStatement pst = sqlConn.prepareStatement(sql)) {
          
            pst.setString(1, JT1.getText());
            pst.setString(2, JT2.getText());
            pst.setString(3, JT3.getText());
            pst.setString(4, JT4.getText());
            pst.setString(5, JT5.getText());
            pst.setString(6, JT6.getText());
            pst.setString(7, JT7.getText());
            pst.setString(8, JT8.getText());
            pst.setString(9, JT9.getText());
                        
            pst.executeUpdate();
            JOptionPane.showMessageDialog(this, "Record added",
                JOptionPane.INFORMATION_MESSAGE);
            upDateDB();
        } // Closes sqlConn and pst 
    } catch (ClassNotFoundException | SQLException ex) { 
        Logger.getLogger(Registration.class.getName()).log(Level.SEVERE, "No record added", ex);
        JOptionPane.showMessageDialog(this, "No record added: " + ex.getMessage(),
            JOptionPane.ERROR_MESSAGE);
    } 

Exsposed中的Typo?

這篇關于在嘗試將java NetBeans j表注冊表的數據放入mysql時,我不斷收到錯誤。的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,

分享到:
標簽:Java 嘗試 收到 放入 數據 注冊表 錯誤
用戶無頭像

網友整理

注冊時間:

網站:5 個   小程序:0 個  文章:12 篇

  • 51998

    網站

  • 12

    小程序

  • 1030137

    文章

  • 747

    會員

趕快注冊賬號,推廣您的網站吧!
最新入駐小程序

數獨大挑戰2018-06-03

數獨一種數學游戲,玩家需要根據9

答題星2018-06-03

您可以通過答題星輕松地創建試卷

全階人生考試2018-06-03

各種考試題,題庫,初中,高中,大學四六

運動步數有氧達人2018-06-03

記錄運動步數,積累氧氣值。還可偷

每日養生app2018-06-03

每日養生,天天健康

體育訓練成績評定2018-06-03

通用課目體育訓練成績評定