Hello,
We have a JAVA application that we developed to process product returns and have been using that application successfully for years. The application utilizes MySQL as the underlying database. Recently, I have been tasked with updating this application (i.e. MySQL, code changes, etc.) so that the app will run compatible with Windows Vista / Windows 7.
One of the problems that I've encountered is a significant delay when attempting to load the MySQL tables with data that is extracted from our ERP system. Data is downloaded into text files (delimited) based on certain criteria provided by the end user, a zip file of this downloaded data is created and then imported into the application. The data appears to load correctly into each of the tables, but the 13 to 15 minutes to load is unacceptable.
Provided below is code used to process one of the downloaded data files (i.e. text files) and upload in to the MySQL tables: (this process is used to upload all the text files).
public void loadReturnHdr(File file, boolean append)
throws IOException, FileNotFoundException, SQLException{
BufferedReader br = new BufferedReader(new FileReader(file));
if(!append){
getPsDeleteAllReturnHdrs().execute();
}
PreparedStatement stmt = getPsInsertReturnHdr();
stmt.clearBatch();
stmt.clearWarnings();
for(String rcd = br.readLine(); rcd != null; rcd = br.readLine()){
setPsInsertReturnHdr(stmt, rcd);
stmt.addBatch();
}
try{
stmt.executeBatch();
}catch(BatchUpdateException be){/* Ignore duplicate key errors */};
br.close();
}
HERE IS THE setPsInsertRetturnHdr method code:
private void setPsInsertReturnHdr(PreparedStatement stmt, String rcd) throws SQLException{
StringTokenizer st = new StringTokenizer(rcd,TAB_NL);
while(st.hasMoreTokens()){
stmt.clearParameters();
stmt.setBigDecimal(1, new BigDecimal(st.nextToken()));
stmt.setString(2, st.nextToken());
stmt.setString(3, st.nextToken());
stmt.setString(4, st.nextToken());
stmt.setString(5, st.nextToken());
stmt.setString(6, st.nextToken());
stmt.setString(7, st.nextToken());
stmt.setString(8, st.nextToken());
stmt.setString(9, st.nextToken());
stmt.setString(10, st.nextToken());
stmt.setString(11, st.nextToken());
try{
stmt.setBigDecimal(12, new BigDecimal(st.nextToken())); }catch(NumberFormatException nfe){
stmt.setBigDecimal(12, new BigDecimal(0));
}
stmt.setString(13, st.nextToken());
stmt.setString(14, st.nextToken());
stmt.setString(15, st.nextToken());
try{
stmt.setBigDecimal(16, new BigDecimal(st.nextToken()));
}catch(NumberFormatException nfe){
stmt.setBigDecimal(16, new BigDecimal(0));
}
stmt.setString(17, st.nextToken());
try{
stmt.setBigDecimal(18, new BigDecimal(st.nextToken()));
}catch(NumberFormatException nfe){
stmt.setBigDecimal(18, new BigDecimal(0));
}
stmt.setString(19, st.nextToken());
stmt.setString(20, st.nextToken());
stmt.setString(21, st.nextToken());
stmt.setString(22, st.nextToken());
stmt.setString(23, st.nextToken());
stmt.setString(24, st.nextToken());
stmt.setString(25, st.nextToken());
stmt.setString(26, st.nextToken());
stmt.setString(27, st.nextToken());
stmt.setBigDecimal(28, ZERO);
stmt.setBigDecimal(29, ZERO);
stmt.setString(30, BLANK);
stmt.setBigDecimal(31, ZERO);
stmt.setBigDecimal(32, ZERO);
stmt.setString(33, st.nextToken());
stmt.setString(34, st.nextToken());
stmt.setString(35, st.nextToken());
}
}
HERE IS THE INSERT STATEMENT
private PreparedStatement getPsInsertReturnHdr() throws SQLException{
if(psInsertReturnHdr == null){
psInsertReturnHdr = conn.prepareStatement(
"insert into returnhdr values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)");
}
return psInsertReturnHdr;
}
Thanks for any assistance,
Randy