- Timestamp:
- 2005-05-16T11:02:50+12:00 (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gsdl3/src/java/org/greenstone/gsdl3/gs3build/database/SQLConnection.java
r8745 r9874 10 10 { 11 11 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) 16 15 { 17 16 this.connection = connection; 17 this.database = database; 18 18 } 19 19 … … 21 21 if (this.connection!=null) { 22 22 try { 23 this.connection.close(); 23 this.connection.close(); 24 24 } catch (Exception e) {} 25 26 this.connection = null; 27 } 25 } 26 this.connection = null; 28 27 } 29 28 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(); 41 31 } 42 32 43 public Statement createStatement() 33 public Statement createStatement() throws SQLException 44 34 { 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(); 66 36 } 67 37 68 38 public boolean connectToDatabase(String database) { 39 if (this.connection != null) { 40 try { 41 this.connection.close(); 42 } catch (Exception e) {} 43 } 69 44 this.connection = GS3SQLConnectionFactory.getConnection(database); 70 45 if (this.connection == null) { 71 46 return false; 72 47 } 48 this.database = database; 73 49 return true; 74 50 } … … 76 52 public boolean dropDatabase(String database) { 77 53 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(); 80 57 } 81 58 catch (SQLException ex){ … … 90 67 try { 91 68 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(); 94 72 } catch (Exception e) { 95 73 System.err.println(e);
Note:
See TracChangeset
for help on using the changeset viewer.