错误MouseListener执行SQL语句

时间:2014-08-27 19:21:29

标签: java sql swing nullpointerexception jbutton

我通过使用我的代码获得此错误。我已经测试了单个步骤,它们都在工作。通过单击一个Button,我从textflields和组合框中获取值,并且应该执行一个Sql语句。 Doese有谁知道错误意味着什么? 谢谢你的帮助

错误:

Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at lastplan.VendorRegistration$2.mouseClicked(VendorRegistration.java:404)
at java.awt.AWTEventMulticaster.mouseClicked(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.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$200(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(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)

代码:

private void ReqBtn(){

    ReqBnt= new JButton("Request");

    ReqBnt.addMouseListener(new MouseAdapter() {

        public void mouseClicked(MouseEvent arg0) {
            if (arg0.getSource() == ReqBnt) {

                String VendN = txtVendN.getText();
                String VendSN = txtVendSN.getText();
                String Ad = txtAd.getText();
                String Ads = txtAds.getText();
                String City = txtCity.getText();
                String Zip = txtZip.getText();
                String UID = txtUID.getText();
                String Reg = txtReg.getText();
                String Rep = txtRep.getText();
                String Tel = txtTel.getText();
                String Fax = txtFax.getText();
                String Mail = txtMail.getText();
                String Iban = txtIban.getText();
                String Bic = txtBic.getText();
                String BInst = txtBInst.getText();
                String VendInfo = txtVendInfo.getText();
                String Flag = "Y";
                String PT = comboPT.getSelectedItem().toString();
                String Ctry = comboCtry.getSelectedItem().toString();
            try{
                try {
                     String sqlx = "SELECT `Abbreviation 2`, `Country English` From `database`.`country_master` " + 
                             "WHERE `Country English` = '" + Ctry + "'";
                     PreparedStatement pstx = conn.prepareStatement(sqlx);
                     ResultSet rs = pstx.executeQuery();
                     while (rs.next()){
                      partCode = rs.getString("Abbreviation 2");
                        }}catch (Exception ex) {
                            System.out.println("Abbreviation Not Found");
                        }

                String sqlFind = "Select max(substring(`Vendor Code`, 3)) From `database`.`vendor_master`";
                try {
                    PreparedStatement pstFind = conn.prepareStatement(sqlFind);
                    ResultSet rs = pstFind.executeQuery();
                    while (rs.next()){
                     partNo = rs.getInt("Vendor Code");
                        }}catch (Exception ex) {
                            partNo = 10001;
                     }


                String VendC = partCode+partNo;

                 try {
                     String sqlx = "SELECT `Abbreviation Use`, `Country English` From `database`.`country_master` " + 
                             "WHERE `Country English` = '" + Ctry + "'";
                     PreparedStatement pstx = conn.prepareStatement(sqlx);
                     ResultSet rs = pstx.executeQuery();
                     while (rs.next()){
                      CtryC = rs.getString("Abbreviation Use");
                        }}catch (Exception ex) {
                            System.out.println("Abbreviation Not Found");
                        }


                    Calendar currentDate = Calendar.getInstance(); //Get the current date
                    SimpleDateFormat formatter= new SimpleDateFormat("dd.MM.yyyy HH:mm:ss");
                    String dateNow = formatter.format(currentDate.getTime());

                try {
                String sql = "INSERT INTO `database`.`vendor_master`(`Vendor Code`,`Vendor Full Name`,`Vendor Short Name`,"+
                                "`Address`,`Address Suffix`,`ZIP Code`,`City`,`Country`,`Country Code`,`UID No`,`Registration No`,"+
                                "`Payment Term`,`Creation Date`,`IBAN`,`BIC`,`Banking Institution`,`Representive`,`Email Address`,"+
                                "`Telefon No`,`Fax`,`Vendor Information`,`Active Flag`) "+
                                "Values('"+VendC+"','"+VendN+"','"+VendSN+"','"+Ad+"','"+Ads+"','"+Zip+"','"+City+"','"+Ctry+"','"+CtryC+"','"+
                                UID+"','"+Reg+"','"+PT+"','"+dateNow+"','"+Iban+"','"+Bic+"','"+BInst+"','"+Rep+"','"+Mail+"','"+Tel+"','"+
                                Fax+"','"+VendInfo+"','"+Flag+"')";


                    PreparedStatement pstExecute = conn.prepareStatement(sql);
                    pstExecute.execute();

                    System.out.println("Vendor Registred");

                    }catch (Exception ex) {
                        System.out.println("Duplicate Data found");
                        }}catch (Exception ex) {
                    System.out.println("Duplicate Data found");
                    }

        }
        }
    });

    ReqBnt.setFont(new Font("Arial", Font.BOLD, 13));
    ReqBnt.setBounds(889, 602, 123, 29);
    frameVendReg.getContentPane().add(ReqBnt);

}

0 个答案:

没有答案