Garbage collection\file release question


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: Garbage collection\file release question

  1. #1
    Join Date
    Jul 2004
    Posts
    13

    Garbage collection\file release question

    I have an app the reads a database populates a table then create a report from that table. The only problem I'm having is when you run the app and there are error in the data that must be fixed before the application can produce the report. The application does not release the database files. I get and sql error that I can not open the file. Does any one know of a way to "release" files so that they could be used again. Action preformed method in my Frame class for "generate" button clicked

    boolean wrongqrt=false;
    read.setYear(((currentDate.getYear()+1900)-yearCB.getSelectedIndex()));
    read.setQuarter(quaterCB.getSelectedIndex());
    checker = new caError(currentDate,read.filePath());
    if(checker.checkDate((quaterCB.getSelectedIndex()+1),yearCB.getSelectedIndex())==false){
    message x =new message(this,true,Errormsg);
    x.show();
    wrongqrt=true;
    }else{
    progress.setVisible(true);
    exit.setEnabled(false);
    view.setEnabled(true);
    // progress.setIndeterminate(true);
    this.update(this.getGraphics());
    read.run();
    // progress.setIndeterminate(false);
    while(read.done()==false){
    progress.setMaximum(read.getMax());
    progress.setValue(read.getCurr());
    this.update(this.getGraphics());
    }
    exit.setEnabled(true);
    if(read.error()==true){
    Errormsg="Your data has errors. An output file cannot be created.\n\r"+
    "Please review the log report and fix ALL errors listed.\n\r"+
    "Once all errors are corrected, please regenerate report.";
    message y = new message(this,true,Errormsg);
    y.show();

    }else{
    read.writeOutput();
    Errormsg="Your report was created sucessfully please send it to Mircal.\n\r File is located in "+read.filePath()+".DAT";
    message y = new message(this,true,Errormsg);
    y.setTitle("Congratulations Your Report Was A Smashing Success!");
    y.show();
    }
    }
    generate.setToolTipText("If you need to Regenerate please close program and try again");
    if(wrongqrt==false){
    generate.setEnabled(false);
    }

    As far as I can tell each of my Statement are closed. and I close the connection to the database when I'm done with my reads. But this does not seem to release the files only after shutting the app down are the files released and able to use again. Here is some of the code associated with the read object for the previous code you are looking at the buildSR_CA method
    Class.forName(Clipper.getDriver());
    conn = DriverManager.getConnection(Clipper.getDatabase(),"","");
    // You need a statement object for each update you preform. You
    // can use the same statement object for queries but updates need
    // to have the own object. At least that is how I got it to work
    Statement stmt = conn.createStatement();
    Statement stmt1 = conn.createStatement();
    Statement stmt2 = conn.createStatement();
    Statement stmt3 = conn.createStatement();
    Statement stmt4 = conn.createStatement();
    Statement stmt5 = conn.createStatement();
    Statement stmt6 = conn.createStatement();
    Statement stmt7 = conn.createStatement();
    Statement stmt8 = conn.createStatement();
    Statement stmt9 = conn.createStatement();
    Statement stmt10 = conn.createStatement();
    //Drop Previous index then Create new one each run of the program.
    stmt9.execute("DROP TABLE SR_CA");
    stmt9.execute(createTable);
    //stmt9.execute("DROP INDEX SR_CA.SR_CA_IDX WHERE SR_CA");
    stmt9.execute("CREATE INDEX SR_CA_IDX ON SR_CA(P_GID,SUB_SERIAL,CONSERIAL)");
    stmt9.close();
    rs= stmt.executeQuery("SELECT * from PROC_SUB WHERE DATE_FROM >=ctod("+start+") AND DATE_FROM<=ctod("+end+") AND PROC_SUB.NO='01' ORDER BY SUB_SERIAL,P_GID");

    //Set auto Commit to false you must do a commit in order to write to the database
    conn.setAutoCommit(false);

    while(rs.next()){
    maxRec++;
    }
    if(whereDis.equalsIgnoreCase("TRUE")){
    progressive.setMaximum(maxRec*7);
    }else{
    progressive.setMaximum(maxRec*8);
    }
    rs= stmt.executeQuery("SELECT * from PROC_SUB WHERE DATE_FROM >=ctod("+start+") AND DATE_FROM<=ctod("+end+") AND PROC_SUB.NO='01' ORDER BY SUB_SERIAL,P_GID");
    while(rs.next()){
    Conserial=rs.getString("CONSERIAL");
    Sub_Serial=rs.getString("SUB_SERIAL");
    DATE_FROM=rs.getDate("DATE_FROM");
    P_GID=rs.getString("P_GID");
    code=rs.getString("CODE");
    update_count=stmt1.executeUpdate("Insert into SR_CA(P_GID,CONSERIAL,SUB_SERIAL,PROC_1,DATE_SER) VALUES('"+P_GID+"','"+Conserial+"','"+Sub_Serial+"','"+code+"',CTOD('"+reorder(DATE_FROM,1 )+"'))" );
    conn.commit();
    progressive.setValue(recCount++);
    progressive.update(progressive.getGraphics());
    } //End While loop for updating Pat ID, Conserial, Sub_Serila Procedure 1 and Date of Service
    stmt1.close();

    } catch (Exception e) {
    if(conn != null){
    try{
    conn.rollback();
    }catch(SQLException x){
    }// End Try catch block
    } // End if(conn != null)
    System.err.println("Got an exception! ");
    System.err.println(e.getMessage());
    e.printStackTrace();
    }// End Outer Try Catch Block
    finally {
    if (conn != null) {
    try {
    conn.close();
    }
    catch (SQLException z) {
    }
    }
    }

    I added the finally to the try catch block in hopes that it would release the files but that did not work. The other Statement stmtX's have similar code and all end with a stmtx.close();

    Thanks for the help

  2. #2
    Join Date
    Jul 2004
    Posts
    13
    One other peice of information I only get the can't read file after I click the generate button on my frame the second time. So I click the generate button the program finds errors that the user must fix one would like the program to be able to redo the same process after they have fixed the errors.


    Thanks again

  3. #3
    Join Date
    Jul 2004
    Posts
    13
    Just in case any one is interested noticed I had not that I did not closed out one of my connection objects which was causing this problem.
    Last edited by jsnico; 06-06-2005 at 01:52 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center