Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Problem with ProgressMonitor  RSS feed

 
Prantik Mazumdar
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All
I am developing a JDBC application, whereby initially am populating a Oracle database (The number of records to be populated extends to about 2 million). In my application, I have use the ProgressMonitor class to display the progress.

The problem is that when the database starts populating, the ProgressMonitor dialog box appears but without any text and progress monitor graphics. Some of the buttons on the main frame vanish as well. Is this a memory problem (my comp is quite a slow one! - 128MB RAM!!)?? or do you'll think it maybe an application error? I have attached the relevant code below. Please advice

***************************Code********************************************************
// Properties of the Load Button
load = userInterface.getDoTask();
load.setText("Load & Insert");
load.setEnabled(false);
load.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
String s = "";
String s1 = "";
String uin = "";
String psr = "";
String psr_acct = "";
String acct_tc = "";
String query_run = "";
String query_insert = "";
String dat_psr = "No";
String dat_acct_tc = "No";
String dat_psr_acct = "No";
String reco = "N";
String cont_ty = "";
String trf_grp = "";
String svc_no = "";
Vector uinlist = new Vector();
Vector psrlist = new Vector();
Vector fields = new Vector();
Vector temp = new Vector();
Vector rowsToInsert = new Vector();
Vector storePSRposition = new Vector();
Vector storeNoAcct = new Vector();
StringTokenizer tokens;
StringTokenizer tokens1;
boolean moreRecords;
int noAcctCounter=0;

progressMonitor = new ProgressMonitor(DVRMain.this,
"Populating Database...", "", 0, tasklength);

try {
//Steps to fill in the uinlist vector from the pilot list file
while((s = in.readLine()) != null) {
tokens = new StringTokenizer(s, "\t");
uin = tokens.nextToken();
uinlist.addElement(uin);
}

//Steps to fill in the psrlist vector from the DAT PSR List file
while((s1 = in1.readLine()) != null) {
tokens1 = new StringTokenizer(s1, "\t");

psr_acct = tokens1.nextToken();
psr = tokens1.nextToken();
cont_ty = tokens1.nextToken();
trf_grp = tokens1.nextToken();
svc_no = tokens1.nextToken();
acct_tc = tokens1.nextToken();

//Instantiate a DAT_check object from the tokens obtained
DAT_check dc = new DAT_check(psr, psr_acct, acct_tc, cont_ty,
trf_grp, svc_no);
psrlist.addElement(dc);
}

statement = connection.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_UPDATABLE);

//Main For Loop
for(int i = 0; i < uinlist.size(); i++) {

double percent = (100.0 * (i + 1)) / tasklength;
progressMonitor.setNote("Process is " + (int) percent + "% complete");
progressMonitor.setProgress(i + 1);

if(progressMonitor.isCanceled()) {
progressMonitor.setProgress(tasklength);
}

//System.out.println("UIN : "+uinlist.elementAt(i));
//Query to extract details about corresponding customer accountse from
//CSI_MRA05 for each UIN in the uinlist vector
query_run = "SELECT CSI_MRA05.CUST_AC, CSI_ACCT.BILLDAY_NO, SVC_NO, " +
"PRDT_ID, CONT_TY, TRF_GRP, PRDT_TY, CPH_DT, PEI " +
"FROM CSI_MRA05, CSI_ACCT " +
"WHERE CSI_MRA05.CUST_AC = CSI_ACCT.CUST_AC AND " +
"CSI_MRA05.CUST_AC IN " +
"(SELECT CUST_AC FROM CSI_ACCT WHERE UIN = '" +
uinlist.elementAt(i) + "')";

//Execute the query
rs = statement.executeQuery(query_run);

if(!rs.next()) {
noAcctCounter++;
System.out.println("Number of UIN's without accounts = " + noAcctCounter);
storeNoAcct.addElement(uinlist.elementAt(i));
}
else {

Vector rows = new Vector();
ResultSetMetaData rsmd = rs.getMetaData();

//Fill the rows of the Vector rows from the ResultSet
do {
rows.addElement(getNextRow(rs, rsmd));
}
while (rs.next());

//Second For-Loop to populate temp Vector
for (int k = 0; k < rows.size(); k++) {
temp = (Vector) rows.elementAt(k);

//Third For-Loop to populate the fields Vector
for (int j = 0; j < 9; j++) {
fields.addElement(temp.elementAt(j));
}

//Fourth For-Loop to populate the psrlist Vector
for (int m = 0; m < psrlist.size(); m++) {
//If the value of PRDT_ID in the fields Vector matches the corresponding
//value in the psrlist vector, mark dat_psr = 'Yes'
if ( (fields.elementAt(3).equals( ( (DAT_check) (psrlist.
elementAt(
m))).getPSR())) &&
(fields.elementAt(4).equals( ( (DAT_check) (psrlist.
elementAt(
m))).getCONT_TY())) &&
(fields.elementAt(5).equals( ( (DAT_check) (psrlist.
elementAt(
m))).getTRF_GRP()))) {
Integer storeValue = new Integer(m);

//System.out.println("PSR :"+fields.elementAt(3)+" found at :"+m);
storePSRposition.addElement(storeValue);
dat_psr = "Yes";
}
}

//If the value of PRDT_ID in the fields Vector matches the corresponding
//value in the psrlist vector AND the value of the CUST_AC in the fields
//Vector matches that of in the psrlist vector, mark dat_acct = 'Yes'
for (int n = 0; n < storePSRposition.size(); n++) {
Integer tempValue = (Integer) storePSRposition.elementAt(n);
int pos = tempValue.intValue();

// System.out.println("Position for checking account :"+pos+" account itself: "+(String)((DAT_check)(psrlist.elementAt(pos))));
if (fields.elementAt(0).equals( ( (DAT_check) (psrlist.
elementAt(
pos))).getPSR_ACCT())) {
dat_psr_acct = "Yes";
}
}

//If the value of CUST_AC in the fields Vector matches the corresponding
//value in the psrlist vector, mark dat_acct_tc = 'Yes'
for (int x = 0; x < psrlist.size(); x++) {
if (fields.elementAt(0).equals( ( (DAT_check) (psrlist.
elementAt(
x))).getACCT_TC())) {
dat_acct_tc = "Yes";
}
}

if ( (dat_psr == "No") &&
(dat_psr_acct == "No") &&
(dat_acct_tc == "No")) {
reco = "Y";
}
else {
reco = "N";
}

//System.out.println(" cust_ac billday_no svc_no prdt_id dat_psr dat_acct dat_tc");
//System.out.println(" "+fields.elementAt(0)+" "+fields.elementAt(1)+" "+fields.elementAt(2)+" "+fields.elementAt(3)+" "+dat_psr+" "+dat_psr_acct+" "+dat_acct_tc);
//Query to insert the retrieved ResultSet into the MIDV04 Database for
//each corresponding UIN searched
query_insert = "INSERT INTO dvr_trial (" +
"uin, CUST_AC, BILLDAY_NO, SVC_NO, PRDT_ID, CONT_TY, TRF_GRP, PRDT_TY, CPH_DT, DAT_PSR, DAT_ACCT, DAT_TC, PEI, RECOMMENDATION " +
") VALUES ('" + uinlist.elementAt(i) + "', '" +
fields.elementAt(0) + "', '" + fields.elementAt(1) + "', '" +
fields.elementAt(2) + "', '" + fields.elementAt(3) + "', '" +
fields.elementAt(4) + "', '" + fields.elementAt(5) + "', '" +
fields.elementAt(6) + "', '" + fields.elementAt(7) + "', '" +
dat_psr + "', '" + dat_psr_acct + "', '" + dat_acct_tc +
"', '" + fields.elementAt(8) + "', '" + reco + "' )";

//Execute Query
int result = statement.executeUpdate(query_insert);

//Set variable and vectors to default values
fields.clear();
storePSRposition.clear();
dat_psr = "No";
dat_psr_acct = "No";
dat_acct_tc = "No";
}
}
}

load.setEnabled(false);
JOptionPane.showMessageDialog(DVRMain.this,
"Database Successfully Populated!", "Loading Completed",
JOptionPane.INFORMATION_MESSAGE);
System.out.println("Number of UIN's without customers in MRA05 = " + noAcctCounter);
} catch(SQLException sqlex) {
sqlex.printStackTrace();
} catch(EOFException eofex) {
load.setEnabled(false);
JOptionPane.showMessageDialog(DVRMain.this, "No more records in file",
"End of File", JOptionPane.ERROR_MESSAGE);
} catch(IOException ioex) {
JOptionPane.showMessageDialog(DVRMain.this, "Error during read from file",
"Read Error", JOptionPane.ERROR_MESSAGE);
}

}
});

***********************************************End of Code********************************************

Thanks a ton
Prantik
 
Joe Ess
Bartender
Posts: 9406
12
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First, welcome to the JavaRanch.
Second, please use the UUB Code tags (they're under the window you enter your question in) to preserve your code formatting.
Third, it is a good idea to narrow down the problem as much as possible. Posting a big block of unformatted text is a good way to get no help.
I'd be willing to bet that you press some button on your gui to start the data transfer, and the code you posted is invoked by that button's actionListener. If this is the case, the gui is not getting updated because you are using the gui thread to do your database work. Simply start another thread to do the database work.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!