Ignore:
Timestamp:
2005-05-16T11:02:50+12:00 (19 years ago)
Author:
kjdon
Message:

merged from branch ant-install-branch: merge 1

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/gsdl3/src/java/org/greenstone/gsdl3/gs3build/database/SQLConnection.java

    r8745 r9874  
    1010{
    1111    protected Connection connection;
    12     protected Statement  statement;
    13 
    14 
    15     public SQLConnection(java.sql.Connection connection)
     12    protected String database;
     13   
     14    public SQLConnection(java.sql.Connection connection, String database)
    1615    {
    1716    this.connection = connection;
     17    this.database = database;
    1818    }
    1919   
     
    2121    if (this.connection!=null) {
    2222        try {
    23         this.connection.close();
     23        this.connection.close();       
    2424        } catch (Exception e) {}
    25        
    26         this.connection = null;
    27     }
     25    }   
     26    this.connection = null;   
    2827    }
    2928   
    30     public boolean execute(String sql)
    31     {
    32     try {
    33         this.statement = this.connection.createStatement();
    34         this.statement.execute(sql);
    35     }
    36     catch (SQLException ex) {
    37         System.out.println(ex);
    38         return false;
    39     }
    40     return true;
     29    public void close() {
     30    finalize();
    4131    }
    4232   
    43     public Statement createStatement()
     33    public Statement createStatement() throws SQLException
    4434    {
    45     try {
    46         return this.connection.createStatement();
    47     }
    48     catch (SQLException ex) {
    49         return null;
    50     }
    51     }
    52    
    53     public Statement getStatement()
    54     {
    55     return this.statement;
    56     }
    57    
    58     public ResultSet getResultSet()
    59     {
    60     try {
    61         return this.statement.getResultSet();
    62     }
    63     catch (SQLException ex) {
    64         return null;
    65     }
     35    return this.connection.createStatement();
    6636    }
    6737   
    6838    public boolean connectToDatabase(String database) {
     39    if (this.connection != null) {
     40        try {
     41        this.connection.close();
     42        } catch (Exception e) {}
     43    }
    6944    this.connection = GS3SQLConnectionFactory.getConnection(database);
    7045    if (this.connection == null) {
    7146        return false;
    7247    }
     48    this.database = database;
    7349    return true;
    7450    }
     
    7652    public boolean dropDatabase(String database) {
    7753    try {
    78         this.statement = this.connection.createStatement();
    79         this.statement.execute("DROP DATABASE "+database+";");
     54        Statement statement = this.connection.createStatement();
     55        statement.execute("DROP DATABASE "+database+";");
     56        statement.close();
    8057    }
    8158    catch (SQLException ex){
     
    9067    try {
    9168        String command = "CREATE DATABASE " + database;
    92         this.statement = this.connection.createStatement();
    93         this.statement.execute(command);
     69        Statement statement = this.connection.createStatement();
     70        statement.execute(command);
     71        statement.close();
    9472    } catch (Exception e) {
    9573        System.err.println(e);
Note: See TracChangeset for help on using the changeset viewer.