作者: luckiejacky 時間: 2013-12-6 17:55 標題: 揮手: 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大致是這樣的
- 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
作者: pl8888 時間: 2013-12-7 03:45
有無任何錯誤信息?
作者: angus0323 時間: 2013-12-7 11:26
你俾個ERROR MESSAGE出黎先啦
作者: Databases 時間: 2013-12-7 14:11
提示: 作者被禁止或刪除 內容自動屏蔽
作者: DarkHero 時間: 2013-12-8 08:30
而家d developer 連報fault 都唔識?
係公司內部佢地係點溝通架呢?
作者: luckiejacky 時間: 2013-12-8 15:53
本帖最後由 luckiejacky 於 2013-12-8 15:57 編輯
照計commit左應該有過喎...
Sorry,真是沒有了error message
不過我有D rollback 會做的
Example
- public int insertOrderDetails(Orders orders, List<OrderDetails> lOrderDetails) throws SQLException
- {
- PreparedStatement pst = null;
-
- String str = "insert into orders (OrderCode, CustomerCode, EmployeeCode, "
- + " PurchaseReason)"
- + " Values (?,?,?,?)";
-
-
-
- try
- {
-
- pst = conn.prepareStatement(str);
- pst.setString(1, orders.getOrderID());
- System.out.println("EmployeeCode " + orders.getEmployeeID());
- pst.setString(2, orders.getCustomerID());
- pst.setString(3, orders.getEmployeeID());
-
-
-
- pst.setInt(4, orders.getReason());
- pst.executeUpdate();
-
-
- }
- catch (SQLException e)
- {
- e.printStackTrace();
- JOptionPane.showMessageDialog(null, "系统错误信息,请联络技术支援");;
- }
- finally {
- close(null, pst, null);
- }
-
- String str2 = " insert into order_details(OrderCode, SKU,"
- + " Quantity, Weight, Price, NetSales) "
- + " Values (?, ?, ?, ?, ?, ?)";
-
-
- try
- {
- pst = conn.prepareStatement(str2);
- final int batchSize = 1000;
- int count = 0;
- for (OrderDetails ot : lOrderDetails) {
- pst.setString(1,ot.getOrderID());
- pst.setString(2,ot.getProductID());
- //pst.setInt(3, ot.getGrossSales());
- pst.setInt(3, ot.getQuantity());
- pst.setInt(4, ot.getWeight());
- pst.setBigDecimal(5, ot.getPrice());
- pst.setBigDecimal(6, ot.getNetSales());
-
-
-
-
- pst.addBatch();
- if(++count % batchSize == 0) {
- pst.executeBatch();
- }
- }
- pst.executeBatch(); // insert remaining records
-
-
-
- }
- // todo don't commit yet, wait for customer to be created
- catch (SQLException e)
- {
- e.printStackTrace();
- JOptionPane.showMessageDialog(null, "系统错误信息,请联络技术支援");;
- conn.rollback();
- return -1;
-
-
- }
- finally
- {
-
- close(null, pst, null);
-
-
-
- }
-
- return 0;
- }
我set個breakpoint at the rollback method
有時會hit 到的,<strike>如果hit 到,是否所有transaction
由開application計起,全部無晒?</strike>
上一個version我sent出去是rollback後不記得
setAutoCommit(true); 會否有些關連?
THX
作者: henrywho 時間: 2013-12-8 18:32
logger 冇 set 落 file 咩?
作者: laputafish 時間: 2013-12-8 20:49
會否系32bit/64bit 問題,唔夾一定行唔到.
作者: bluenemo 時間: 2013-12-8 21:05
怎可Test到隻record已經在Database之內?
唔係enquire個DB咪知囉?
作者: cloud417 時間: 2013-12-8 22:43
pst.executeUpdate();
this statement return the number of row being updated
