本帖最後由 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大致是這樣的
- btnPanel.getAddCustomerBtn().addActionListener(new java.awt.event.ActionListener() {
- @Override
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- try {
- createCustomerBtnActionPerformed(evt);
- } catch (SQLException ex) {
- JOptionPane.showMessageDialog(null, "系统错误信息,请联络技术支援");
- Logger.getLogger(CreateCustomer.class.getName()).log(Level.SEVERE, null, ex);
- } catch (BadLocationException ex) {
- JOptionPane.showMessageDialog(null, "系统错误信息,请联络技术支援");
- Logger.getLogger(CreateCustomer.class.getName()).log(Level.SEVERE, null, ex);
- } catch (IOException ex) {
- Logger.getLogger(CreateCustomer.class.getName()).log(Level.SEVERE, null, ex);
- }
- }
- private void createCustomerBtnActionPerformed(ActionEvent evt) throws SQLException, BadLocationException, IOException {
- Customer customer = new Customer();
-
- boolean bBlackList = db.checkBlackList(custPanel.getCustID());
- boolean bDuplicate = db.checkDuplicate(custPanel.getFirstName(), custPanel.getLastName(), custPanel.getMobilePhoneNo());
-
- if (bBlackList)
- {
- JOptionPane.showMessageDialog(null, "会员已列入黑名单", "会员已列入黑名单", JOptionPane.INFORMATION_MESSAGE);
- }
- else if (bDuplicate)
- {
- JOptionPane.showMessageDialog(null, "会员编号重复", "会员编号重复", JOptionPane.INFORMATION_MESSAGE);
- }
- else
- {
- try
- {
- customer.setCustId(custPanel.getCustID());
- customer.setAddress(custPanel.getAddress());
- customer.setAgeGroup(custPanel.getAgeGroup());
- customer.setResidence(custPanel.getResidence());
-
- customer.setConvenientContactTime(custPanel.getConvenientContactTime());
-
- customer.setDOB(custPanel.getDOB().toString());
- customer.setEmail(custPanel.getEmail());
-
- customer.setFirstName(custPanel.getFirstName());
- customer.setLastName(custPanel.getLastName());
-
- customer.setIdCardNo(custPanel.getIDCardNo());
- customer.setSalaryRange(custPanel.getSalaryRange());
- customer.setJobDuty(custPanel.getDuty());
- customer.setMobilePhoneNo(custPanel.getMobilePhoneNo());
- customer.setOccupation(custPanel.getOccupation());
-
- customer.setPostalCode(custPanel.getPostalCode());
- customer.setPreferredContactMethodID(custPanel.getContactMethod());
- customer.setQQ(custPanel.getQQ());
- customer.setSex(custPanel.getSex());
-
-
- String s = custPanel.getMemoryDate();
- if (s == null)
- {
- customer.setMemoryDate(null);
- }
- else
- {
- customer.setMemoryDate(s);
- }
- customer.setMemoryDateReason(custPanel.getMemoryReasons());
- customer.setEducation(custPanel.getEducation());
- customer.setBonusPoints(custPanel.getBonusPoints());
-
- customer.setRegisterDate(custPanel.getRegisteredDate());
- customer.setCreatePerson(custPanel.getCreatePerson());
- customer.setGMCustomer(false);
-
- System.out.println("Customer is " + customer.toString());
- if (
- customer.getAgeGroup() != -1 &&
- customer.getResidence() != -1 &&
-
- customer.getDOB() != null &&
-
- !customer.getFirstName().equals("") &&
- customer.getJobDuty() != -1 &&
- !customer.getLastName().equals("") &&
-
- !customer.getMobilePhoneNo().equals("") &&
- customer.getOccupation() != -1 &&
- customer.getSex() != 'U' &&
-
- !customer.getCreatePerson().equals(""))
-
- {
- if (db.insertCustomer(customer, -1) != -1)
- {java.util.Date date = new java.util.Date();
- String logCode = UtilityFactory.generateLogID(db);
-
- UtilityFactory.eventLogger(db, customer.getCustID(), -1, null, logCode, 1, -1, "", parent.getPasswordDialog().getUser(), true, date );
- CreateSales cs = new CreateSales("/resources/topbar_createSales.png", db, customer.getCustID(), parent ,false);
- int result = cs.createSalesTransaction();
- //cs.setVisible(true);
-
- JOptionPane.showMessageDialog(null,"成功新增会员", "成功新增会员", JOptionPane.INFORMATION_MESSAGE);
- boolean vip = db.isVIP(custID);
- if (vip)
- {
- String lc = UtilityFactory.generateLogID(db);
- UtilityFactory.eventLogger(db, customer.getCustID(),-1, null,lc, 2, -1, "", parent.getPasswordDialog().getUser(), true, date );
- }
- parent.refreshPanels();
-
- }
- }
- else
- {
- JOptionPane.showMessageDialog(null, "新增会员失败");
- parent.refreshPanels();
- }
- }
- catch (Exception e)
- {
-
- JOptionPane.showMessageDialog(null, "新增会员失败");
- parent.refreshPanels();
- }
-
- }
-
- }
-
- });
複製代碼
- public int insertCustomer(Customer customer, int buttonState) throws SQLException {
-
- PreparedStatement pst = null;
-
- try
- {
- String str = "insert into customer ( CustomerCode,"
- + " LastName,"
- + "FirstName,"
- + " Residence, "
- + "PreferredContactMethodID,"
- + " Sex,"
- + " Address, "
- + " JobDutyID,"
- + " ConvenientContactTimeID,"
- + "IDCardNumber, "
-
- + "DOB,"
- + "MobilePhoneNumber, Email,"
- + "PostalCode, QQ,"
- + "AgeGroupID, OccupationID, WeiShun, SalaryRangeID,"
- + "MemoryReasonID, MemoryDate, EducationID, BonusPoints ,"
- // 25
- + " GMCustomer, "
- // 26
- + " BlackListed, RegisterDate, CreatePerson"
- // 29
- + " ) VALUES ("
- + "?,?,?,?,?,?,?,?,?,?,"
- + "?,?,?,?,?,?,?,?,?,?,"
- + "?,?,?,?," // GM
- + "FALSE,?,?)"; // 29
-
- pst = conn.prepareStatement(str);
- pst.setString(1, customer.getCustID());
- pst.setString(2, customer.getLastName());
- pst.setString(3, customer.getFirstName());
- pst.setInt(4, customer.getResidence());
- pst.setInt(5, customer.getPreferredContactMethodID());
- pst.setString(6, String.valueOf(customer.getSex()));
- //pst.setString(8, customer.getOfficeContactNumber());
- pst.setString(7, customer.getAddress());
- pst.setInt(8, customer.getJobDuty());
- pst.setInt(9, customer.getConvenientContactTime());
- pst.setString(10, customer.getIdCardNo());
- if (customer.getDOB() == null)
- pst.setDate(11, null);
- else
- pst.setDate(11, java.sql.Date.valueOf(customer.getDOB()));
- pst.setString(12, customer.getMobilePhoneNo());
- pst.setString(13, customer.getEmail());
- pst.setString(14, customer.getPostalCode());
- pst.setString(15, customer.getQQ());
- pst.setInt(16, customer.getAgeGroup());
- pst.setInt(17, customer.getOccupation());
- pst.setString(18, customer.getWeiShun());
- pst.setInt(19, customer.getSalaryRange());
- pst.setInt(20, customer.getMemoryDateReason());
- if (customer.getMemoryDate() == null)
- pst.setDate(21, null);
- else
- pst.setDate(21, java.sql.Date.valueOf(customer.getMemoryDate()));
-
- pst.setInt(22, customer.getEducation());
-
-
- pst.setInt(23, customer.getBonusPoints());
- pst.setBoolean(24, customer.isGMCustomer());
- if (customer.getRegisterDate() == null)
- {
- pst.setDate(25, null);
- }
- else
- {
- pst.setDate(25, java.sql.Date.valueOf(customer.getRegisterDate()));
- }
-
- pst.setString(26, customer.getCreatePerson());
- pst.executeUpdate();
- }
- catch (SQLException ex)
- {
- ex.printStackTrace();
- JOptionPane.showMessageDialog(null, "系统错误信息,请联络技术支援");;
-
-
- return -1;
- }
- finally
- {
- close(null, pst, null);
- }
-
- return 0;
-
-
-
- }
-
複製代碼
真係唔知什麼事,有冇CHING可指點迷津?
怎可Test到隻record已經在Database之內?
THX |