如何修复“对于输入字符串”“”

时间:2019-05-22 18:29:58

标签: java sql

我正在处理我的项目,但我不知道如何解决此异常。

当我的用户没有信用卡号时,我可以毫无问题地添加一个和钱。但是,当我再次登录并要添加钱时,必须在TextField(numberOfCreditCardTF)中输入他的信用卡号,然后按“添加”按钮。当我按下此按钮时,在控制台中会出现异常。

存在此问题的行位于220:

String querryUpdateMoney = "UPDATE
     money SET moneyCard=" +
     Long.parseLong(cg.moneyOnCreditCardTF.getText().trim()) + " WHERE
     numberCard=" +
     Long.parseLong(cg.numberOfCreditCardTF.getText().trim());

这是我的代码:

cg.addMoneyBtn.addActionListener(e1 -> {

                        String query = "SELECT * FROM user WHERE username = '" + cg.ulogovanikorisnik.getText() + "'";
                        ResultSet result = null;
                        try {
                            result = sqlConnector.select(query);
                        } catch (SQLException ex) {
                            ex.printStackTrace();
                        }
                        try {
                            if (result.next()) {
                                Long numberCard= Long.valueOf(cg.numberOfCreditCardTF.getText());
                                String upit = "SELECT * FROM money WHERE numberCard="+numberCard;
                                ResultSet resultSet = null;

                                try {
                                    resultSet = sqlConnector.select(upit);
                                    System.out.println(upit);
                                } catch (SQLException ex) {
                                    ex.printStackTrace();
                                }
                                try {

                                    if (!resultSet.next()) {
                                        String query2 = "INSERT INTO money (idUlogovani,numberCard,moneyCard)" +
                                                " VALUES(" + result.getLong("id") + "," + Long.parseLong(cg.numberOfCreditCardTF.getText()) + "," + 0 + ")";

                                        int rs = sqlConnector.iudQuerry(query2);
                                        infoMessage("Number of credit card is correct", "Credit Card INFO");
                                        cg.moneyOnCreditCardTF.setVisible(true);
                                        cg.moneyOnCreditCardLbl.setVisible(true);
                                        cg.numberOfCreditCardTF.setEditable(false);
                                        cg.addMoneyBtn.setText("Input money");
                                        cg.addMoneyBtn.setBounds(350, 280, 283, 36);

                                    } else {
                                        String querryUpdateMoney = "UPDATE money SET moneyCard=" + Long.parseLong(cg.moneyOnCreditCardTF.getText().trim()) + " WHERE numberCard=" + Long.parseLong(cg.numberOfCreditCardTF.getText().trim());
                                        int rsUpdate = sqlConnector.iudQuerry(querryUpdateMoney);
                                        System.out.println("ok sve");
                                    }
                                } catch (NumberFormatException ex) {
                                    ex.printStackTrace();
                                } catch (SQLException ex) {
                                    ex.printStackTrace();
                                }
                            }
                        } catch (NumberFormatException ex) {
                            ex.printStackTrace();
                        } catch (SQLException ex) {
                            ex.printStackTrace();
                        }
                    });
                });

这是个例外:

  

java.lang.NumberFormatException:对于输入字符串:“”         在java.base / java.lang.NumberFormatException.forInputString(NumberFormatException.java:68)         在java.base / java.lang.Long.parseLong(Long.java:709)         在java.base / java.lang.Long.parseLong(Long.java:824)         在Graphics.lambda $ main $ 1(Graphics.java:220)         在java.desktop / javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1967)         在java.desktop / javax.swing.AbstractButton $ Handler.actionPerformed(AbstractButton.java:2308)         在java.desktop / javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:405)         在java.desktop / javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:262)         在java.desktop / javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:279)         在java.desktop / java.awt.Component.processMouseEvent(Component.java:6632)         在java.desktop / javax.swing.JComponent.processMouseEvent(JComponent.java:3342)         在java.desktop / java.awt.Component.processEvent(Component.java:6397)         在java.desktop / java.awt.Container.processEvent(Container.java:2263)         在java.desktop / java.awt.Component.dispatchEventImpl(Component.java:5008)         在java.desktop / java.awt.Container.dispatchEventImpl(Container.java:2321)         在java.desktop / java.awt.Component.dispatchEvent(Component.java:4840)         在java.desktop / java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4918)         在java.desktop / java.awt.LightweightDispatcher.processMouseEvent(Container.java:4547)         在java.desktop / java.awt.LightweightDispatcher.dispatchEvent(Container.java:4488)         在java.desktop / java.awt.Container.dispatchEventImpl(Container.java:2307)         在java.desktop / java.awt.Window.dispatchEventImpl(Window.java:2762)         在java.desktop / java.awt.Component.dispatchEvent(Component.java:4840)         在java.desktop / java.awt.EventQueue.dispatchEventImpl(EventQueue.java:772)         在java.desktop / java.awt.EventQueue $ 4.run(EventQueue.java:721)         在java.desktop / java.awt.EventQueue $ 4.run(EventQueue.java:715)         在java.base / java.security.AccessController.doPrivileged(AccessController.java:389)         在java.base / java.security.ProtectionDomain $ JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:85)         在java.base / java.security.ProtectionDomain $ JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:95)         在java.desktop / java.awt.EventQueue $ 5.run(EventQueue.java:745)         在java.desktop / java.awt.EventQueue $ 5.run(EventQueue.java:743)         在java.base / java.security.AccessController.doPrivileged(AccessController.java:389)         在java.base / java.security.ProtectionDomain $ JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:85)         在java.desktop / java.awt.EventQueue.dispatchEvent(EventQueue.java:742)         在java.desktop / java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:203)         在java.desktop / java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:124)         在java.desktop / java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:113)         在java.desktop / java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:109)         在java.desktop / java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)         在java.desktop / java.awt.EventDispatchThread.run(EventDispatchThread.java:90)

0 个答案:

没有答案