揮手: Java Application Deployment

本帖最後由 luckiejacky 於 2013-12-6 18:02 編輯

我有個Java Swing Application,在香港Windows 7 development platform
同叧一部機試過可以Save到,但一到大陸,就Save唔到
我的Development platform 是Win7,但production platform 是XP
已升了SP3 同最新JRE
DBMS: JavaDB
我是用在Java JDK 內的db folder內的Derby.jar driver

我的DB Operation大致是這樣的
  1. btnPanel.getAddCustomerBtn().addActionListener(new java.awt.event.ActionListener() {
  2.          @Override
  3.          public void actionPerformed(java.awt.event.ActionEvent evt) {
  4.              try {
  5.                  createCustomerBtnActionPerformed(evt);
  6.              } catch (SQLException ex) {
  7.                  JOptionPane.showMessageDialog(null, "系统错误信息,请联络技术支援");
  8.                  Logger.getLogger(CreateCustomer.class.getName()).log(Level.SEVERE, null, ex);
  9.              } catch (BadLocationException ex) {
  10.                  JOptionPane.showMessageDialog(null, "系统错误信息,请联络技术支援");
  11.                  Logger.getLogger(CreateCustomer.class.getName()).log(Level.SEVERE, null, ex);
  12.              } catch (IOException ex) {
  13.                  Logger.getLogger(CreateCustomer.class.getName()).log(Level.SEVERE, null, ex);
  14.              }
  15.             }

  16.             private void createCustomerBtnActionPerformed(ActionEvent evt) throws SQLException, BadLocationException, IOException {
  17.                  Customer customer = new Customer();
  18.                  
  19.                  boolean bBlackList = db.checkBlackList(custPanel.getCustID());
  20.                  boolean bDuplicate = db.checkDuplicate(custPanel.getFirstName(), custPanel.getLastName(),  custPanel.getMobilePhoneNo());
  21.                  
  22.                  if (bBlackList)
  23.                  {
  24.                      JOptionPane.showMessageDialog(null, "会员已列入黑名单", "会员已列入黑名单", JOptionPane.INFORMATION_MESSAGE);
  25.                  }
  26.                  else if (bDuplicate)
  27.                  {
  28.                      JOptionPane.showMessageDialog(null, "会员编号重复", "会员编号重复", JOptionPane.INFORMATION_MESSAGE);
  29.                  }
  30.                  else
  31.                  {
  32.                      try
  33.                      {
  34.                         customer.setCustId(custPanel.getCustID());
  35.                        customer.setAddress(custPanel.getAddress());
  36.                        customer.setAgeGroup(custPanel.getAgeGroup());
  37.                        customer.setResidence(custPanel.getResidence());
  38.   
  39.                        customer.setConvenientContactTime(custPanel.getConvenientContactTime());
  40.                         
  41.                        customer.setDOB(custPanel.getDOB().toString());
  42.                        customer.setEmail(custPanel.getEmail());

  43.                        customer.setFirstName(custPanel.getFirstName());
  44.                        customer.setLastName(custPanel.getLastName());
  45.    
  46.                        customer.setIdCardNo(custPanel.getIDCardNo());
  47.                        customer.setSalaryRange(custPanel.getSalaryRange());
  48.                        customer.setJobDuty(custPanel.getDuty());
  49.                        customer.setMobilePhoneNo(custPanel.getMobilePhoneNo());
  50.                        customer.setOccupation(custPanel.getOccupation());
  51.      
  52.                        customer.setPostalCode(custPanel.getPostalCode());
  53.                        customer.setPreferredContactMethodID(custPanel.getContactMethod());
  54.                        customer.setQQ(custPanel.getQQ());
  55.                        customer.setSex(custPanel.getSex());
  56.       

  57.                        String s = custPanel.getMemoryDate();
  58.                        if (s == null)
  59.                        {
  60.                            customer.setMemoryDate(null);
  61.                        }
  62.                        else
  63.                        {
  64.                             customer.setMemoryDate(s);
  65.                        }
  66.                        customer.setMemoryDateReason(custPanel.getMemoryReasons());
  67.                        customer.setEducation(custPanel.getEducation());

  68.                        customer.setBonusPoints(custPanel.getBonusPoints());
  69.                        
  70.                        customer.setRegisterDate(custPanel.getRegisteredDate());

  71.                        customer.setCreatePerson(custPanel.getCreatePerson());
  72.                        customer.setGMCustomer(false);


  73.   
  74.                        System.out.println("Customer is " + customer.toString());


  75.                        if (
  76.                                customer.getAgeGroup() != -1 &&
  77.                                customer.getResidence() != -1 &&
  78.                            
  79.                                customer.getDOB() != null &&

  80.                              
  81.                                !customer.getFirstName().equals("") &&
  82.                                 customer.getJobDuty() != -1 &&
  83.                                !customer.getLastName().equals("") &&
  84.                               
  85.                                !customer.getMobilePhoneNo().equals("") &&
  86.                                customer.getOccupation() != -1 &&
  87.                                customer.getSex() != 'U' &&
  88.                              
  89.                                !customer.getCreatePerson().equals(""))
  90.                            
  91.                               {
  92.                                   if (db.insertCustomer(customer, -1) != -1)
  93.                                     {java.util.Date date = new java.util.Date();
  94.                                       String logCode = UtilityFactory.generateLogID(db);
  95.                                       
  96.                                      UtilityFactory.eventLogger(db, customer.getCustID(), -1,  null, logCode,  1, -1, "", parent.getPasswordDialog().getUser(), true, date );
  97.                                     CreateSales cs = new CreateSales("/resources/topbar_createSales.png", db, customer.getCustID(),  parent ,false);
  98.                                     int result = cs.createSalesTransaction();
  99.                                     //cs.setVisible(true);

  100.                                     JOptionPane.showMessageDialog(null,"成功新增会员",  "成功新增会员", JOptionPane.INFORMATION_MESSAGE);

  101.                                     boolean vip = db.isVIP(custID);
  102.                                     if (vip)
  103.                                     {
  104.                                          String lc = UtilityFactory.generateLogID(db);
  105.                                         UtilityFactory.eventLogger(db, customer.getCustID(),-1, null,lc, 2, -1, "", parent.getPasswordDialog().getUser(), true, date );
  106.                                     }

  107.                                     parent.refreshPanels();
  108.                                     
  109.                                   }
  110.                               }
  111.                               else
  112.                               {
  113.                                   JOptionPane.showMessageDialog(null, "新增会员失败");
  114.                                    parent.refreshPanels();

  115.                               }        
  116.                      }
  117.                      catch (Exception e)
  118.                      {
  119.                                    
  120.                                   JOptionPane.showMessageDialog(null, "新增会员失败");
  121.                                    parent.refreshPanels();
  122.                      }
  123.                         
  124.                   }
  125.                  
  126.              }
  127.             
  128.         });
複製代碼

  1. public int insertCustomer(Customer customer, int buttonState) throws SQLException {

  2.         PreparedStatement pst = null;
  3.          
  4.         try
  5.         {
  6.             String str = "insert into customer ( CustomerCode,"
  7.                     + " LastName,"
  8.                     + "FirstName,"
  9.                     + " Residence, "
  10.                     + "PreferredContactMethodID,"
  11.                     + " Sex,"
  12.                     + " Address, "
  13.                     + " JobDutyID,"
  14.                     + " ConvenientContactTimeID,"
  15.                     + "IDCardNumber, "
  16.                      
  17.                     + "DOB,"
  18.                     + "MobilePhoneNumber, Email,"
  19.                     + "PostalCode, QQ,"
  20.                     + "AgeGroupID, OccupationID, WeiShun, SalaryRangeID,"
  21.                     + "MemoryReasonID, MemoryDate, EducationID,  BonusPoints ,"
  22.                      // 25
  23.                     + " GMCustomer, "
  24.                     // 26
  25.                     + " BlackListed, RegisterDate, CreatePerson"
  26.                     // 29
  27.                     + " ) VALUES ("
  28.                     + "?,?,?,?,?,?,?,?,?,?,"
  29.                     + "?,?,?,?,?,?,?,?,?,?,"
  30.                     + "?,?,?,?," // GM
  31.                     + "FALSE,?,?)"; // 29
  32.             
  33.             pst = conn.prepareStatement(str);
  34.             pst.setString(1, customer.getCustID());
  35.             pst.setString(2, customer.getLastName());
  36.             pst.setString(3, customer.getFirstName());
  37.            pst.setInt(4, customer.getResidence());
  38.             pst.setInt(5, customer.getPreferredContactMethodID());
  39.             pst.setString(6, String.valueOf(customer.getSex()));
  40.             //pst.setString(8, customer.getOfficeContactNumber());
  41.             pst.setString(7, customer.getAddress());
  42.             pst.setInt(8, customer.getJobDuty());
  43.             pst.setInt(9, customer.getConvenientContactTime());
  44.             pst.setString(10, customer.getIdCardNo());
  45.             if (customer.getDOB() == null)
  46.                 pst.setDate(11, null);
  47.             else
  48.                 pst.setDate(11, java.sql.Date.valueOf(customer.getDOB()));
  49.              pst.setString(12, customer.getMobilePhoneNo());
  50.             pst.setString(13, customer.getEmail());
  51.             pst.setString(14, customer.getPostalCode());
  52.             pst.setString(15, customer.getQQ());
  53.             pst.setInt(16, customer.getAgeGroup());
  54.             pst.setInt(17, customer.getOccupation());
  55.             pst.setString(18, customer.getWeiShun());
  56.             pst.setInt(19, customer.getSalaryRange());
  57.             pst.setInt(20, customer.getMemoryDateReason());
  58.             if (customer.getMemoryDate() == null)
  59.                 pst.setDate(21, null);
  60.             else
  61.                 pst.setDate(21, java.sql.Date.valueOf(customer.getMemoryDate()));
  62.             
  63.             pst.setInt(22, customer.getEducation());
  64.             
  65.             
  66.             pst.setInt(23, customer.getBonusPoints());
  67.             pst.setBoolean(24, customer.isGMCustomer());
  68.             if (customer.getRegisterDate() == null)
  69.             {
  70.                 pst.setDate(25, null);
  71.             }
  72.             else
  73.             {
  74.                 pst.setDate(25, java.sql.Date.valueOf(customer.getRegisterDate()));
  75.             }
  76.             
  77.             pst.setString(26, customer.getCreatePerson());
  78.             pst.executeUpdate();
  79.         }
  80.         catch (SQLException ex)
  81.         {
  82.             ex.printStackTrace();
  83.             JOptionPane.showMessageDialog(null, "系统错误信息,请联络技术支援");;
  84.          
  85.             
  86.             return -1;
  87.         }
  88.         finally
  89.         {
  90.             close(null, pst, null);
  91.         }
  92.         
  93.         return 0;
  94.             
  95.             
  96.          
  97.     }
複製代碼


真係唔知什麼事,有冇CHING可指點迷津?
怎可Test到隻record已經在Database之內?
THX

有無任何錯誤信息?

TOP

你俾個ERROR MESSAGE出黎先啦

TOP

提示: 作者被禁止或刪除 內容自動屏蔽

TOP

而家d developer 連報fault 都唔識?
係公司內部佢地係點溝通架呢?

TOP

本帖最後由 luckiejacky 於 2013-12-8 15:57 編輯

照計commit左應該有過喎...
Sorry,真是沒有了error message
不過我有D rollback 會做的
Example
  1.   public int insertOrderDetails(Orders orders, List<OrderDetails> lOrderDetails) throws SQLException
  2.     {
  3.         PreparedStatement pst = null;
  4.          
  5.                 String str = "insert into orders (OrderCode, CustomerCode, EmployeeCode,  "
  6.                 + " PurchaseReason)"
  7.                 + " Values (?,?,?,?)";
  8.         
  9.          
  10.          
  11.         try
  12.         {
  13.             
  14.             pst = conn.prepareStatement(str);
  15.             pst.setString(1, orders.getOrderID());
  16.             System.out.println("EmployeeCode " + orders.getEmployeeID());
  17.             pst.setString(2, orders.getCustomerID());
  18.             pst.setString(3, orders.getEmployeeID());
  19.             
  20.             
  21.             
  22.             pst.setInt(4, orders.getReason());
  23.             pst.executeUpdate();
  24.             
  25.             
  26.         }
  27.         catch (SQLException e)
  28.         {
  29.             e.printStackTrace();
  30.            JOptionPane.showMessageDialog(null, "系统错误信息,请联络技术支援");;
  31.         }
  32.         finally {
  33.             close(null, pst, null);
  34.         }
  35.             
  36.         String str2 = " insert into order_details(OrderCode, SKU,"
  37.                  + " Quantity,   Weight, Price, NetSales) "
  38.                 + " Values (?, ?, ?, ?, ?, ?)";
  39.         
  40.                  
  41.          try
  42.          {
  43.                 pst = conn.prepareStatement(str2);

  44.                 final int batchSize = 1000;
  45.                 int count = 0;

  46.                 for (OrderDetails ot : lOrderDetails) {

  47.                         pst.setString(1,ot.getOrderID());
  48.                         pst.setString(2,ot.getProductID());
  49.                         //pst.setInt(3, ot.getGrossSales());
  50.                         pst.setInt(3, ot.getQuantity());
  51.                         pst.setInt(4, ot.getWeight());

  52.                         pst.setBigDecimal(5, ot.getPrice());
  53.                         pst.setBigDecimal(6, ot.getNetSales());

  54.                         
  55.                         
  56.                         
  57.                         pst.addBatch();

  58.                         if(++count % batchSize == 0) {
  59.                                 pst.executeBatch();
  60.                         }
  61.              }
  62.             pst.executeBatch(); // insert remaining records
  63.             
  64.             
  65.             
  66.          }
  67.          // todo don't commit yet, wait for customer to be created
  68.          catch (SQLException e)
  69.          {
  70.              e.printStackTrace();
  71.              JOptionPane.showMessageDialog(null, "系统错误信息,请联络技术支援");;
  72.              conn.rollback();
  73.              return -1;
  74.             
  75.             
  76.          }
  77.          finally
  78.          {

  79.             close(null, pst, null);
  80.               
  81.    
  82.   
  83.          }
  84.    
  85.          return 0;
  86.   }
複製代碼

我set個breakpoint at the rollback method
有時會hit 到的,<strike>如果hit 到,是否所有transaction
由開application計起,全部無晒?</strike>
上一個version我sent出去是rollback後不記得
setAutoCommit(true); 會否有些關連?
THX

TOP

logger 冇 set 落 file 咩?

TOP

會否系32bit/64bit 問題,唔夾一定行唔到.

TOP

怎可Test到隻record已經在Database之內?

唔係enquire個DB咪知囉?

TOP

pst.executeUpdate();
this statement return the number of row being updated

TOP