Ignore:
Timestamp:
2005-05-10T15:48:11+12:00 (19 years ago)
Author:
kjdon
Message:

do a lot more tidying up. close the previous statement before creating a new one - if you don't close a statement it doesn't free up its memory resources. also remember the database now so we can clone the connection - need to create a new connection if we want to execute something while we are still using results from a previous execution - when a statement is closed, so is its resultset

Location:
branches/ant-install-branch/gsdl3/src/java/org/greenstone/gsdl3/gs3build/database
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/ant-install-branch/gsdl3/src/java/org/greenstone/gsdl3/gs3build/database/GS3SQLConnection.java

    r8773 r9847  
    1414{
    1515
    16     public GS3SQLConnection(java.sql.Connection connection)
     16    public GS3SQLConnection(java.sql.Connection connection, String database)
    1717    {
    18     super(connection);
     18    super(connection, database);
    1919    }
    2020   
     
    2525  }
    2626   
    27 
     27    public GS3SQLConnection cloneConnection() {
     28    GS3SQLConnection conn = GS3SQLConnectionFactory.getGS3SQLConnection(this.database);
     29    return conn;
     30    }
    2831  /**
    2932   *  Initialise a collection for use.
     
    224227      statement.execute(classData.toString());
    225228
     229      statement.close();
    226230      //
    227231      // END OF GSDL TABLES
     
    232236    {
    233237      System.out.println(ex.toString());
     238      if (statement != null) {
     239      try {
     240          statement.close();
     241      } catch (Exception e){}
     242      statement = null;
     243      }
    234244      return false;
    235245    }
  • branches/ant-install-branch/gsdl3/src/java/org/greenstone/gsdl3/gs3build/database/GS3SQLConnectionFactory.java

    r8745 r9847  
    3232        return null;
    3333    }
    34     return new SQLConnection(c);
     34    return new SQLConnection(c, database);
    3535    }
    3636
     
    4242        return null;
    4343    }
    44     return new GS3SQLConnection(c);
     44    return new GS3SQLConnection(c, database);
    4545    }
    4646
  • branches/ant-install-branch/gsdl3/src/java/org/greenstone/gsdl3/gs3build/database/SQLConnection.java

    r8745 r9847  
    1111    protected Connection connection;
    1212    protected Statement  statement;
    13 
    14 
    15     public SQLConnection(java.sql.Connection connection)
     13    protected String database;
     14   
     15    public SQLConnection(java.sql.Connection connection, String database)
    1616    {
    1717    this.connection = connection;
     18    this.database = database;
    1819    }
    1920   
     
    2122    if (this.connection!=null) {
    2223        try {
    23         this.connection.close();
     24        this.connection.close();       
    2425        } catch (Exception e) {}
    25        
    26         this.connection = null;
    2726    }
     27    if (this.statement!=null) {
     28        try {
     29        this.statement.close();     
     30        } catch (Exception e) {}
     31    }
     32   
     33    this.connection = null;   
     34    this.statement = null;
     35
    2836    }
    2937   
     38    public void close() {
     39    finalize();
     40    }
     41   
    3042    public boolean execute(String sql)
    3143    {
    3244    try {
     45        if (this.statement != null) {
     46        this.statement.close();
     47        }
    3348        this.statement = this.connection.createStatement();
    3449        this.statement.execute(sql);
     
    4156    }
    4257   
     58    public void closeStatement() {
     59    try {
     60        if (this.statement != null) {
     61        this.statement.close();
     62        }
     63    } catch (Exception e) {}
     64       
     65    }
    4366    public Statement createStatement()
    4467    {
     
    6790   
    6891    public boolean connectToDatabase(String database) {
     92    if (this.connection != null) {
     93        try {
     94        this.connection.close();
     95        } catch (Exception e) {}
     96    }
    6997    this.connection = GS3SQLConnectionFactory.getConnection(database);
    7098    if (this.connection == null) {
    7199        return false;
    72100    }
     101    this.database = database;
    73102    return true;
    74103    }
     
    78107        this.statement = this.connection.createStatement();
    79108        this.statement.execute("DROP DATABASE "+database+";");
     109        this.statement.close();
    80110    }
    81111    catch (SQLException ex){
     
    92122        this.statement = this.connection.createStatement();
    93123        this.statement.execute(command);
     124        this.statement.close();
    94125    } catch (Exception e) {
    95126        System.err.println(e);
Note: See TracChangeset for help on using the changeset viewer.