Changeset 21321
- Timestamp:
- 2009-12-09T17:04:54+13:00 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/trunk/greenstone3/src/java/org/greenstone/gsdl3/sql/derby/DerbyDBWrapper.java
r21303 r21321 24 24 protected SQLStatements sqlState = null; 25 25 protected Connection connection = null; 26 protected Statement statement = null;27 26 protected static Logger logger = Logger.getLogger(org.greenstone.gsdl3.sql.derby.DerbyDBWrapper.class.getName()); 28 27 … … 58 57 59 58 public boolean openConnection(String databasepath){ 59 if(connection != null) return true; 60 60 61 connection = sqlServer.connect(databasepath); 61 62 62 if (connection == null) return false; 63 64 63 try{ 65 connection.setAutoCommit(false); 66 statement = connection.createStatement(); 64 connection.setAutoCommit(true); 67 65 } 68 66 catch(SQLException sqle){ … … 74 72 75 73 public boolean openAndCreateConnection(String databasepath){ 74 if(connection != null) return true; 76 75 connection = sqlServer.connectAndCreate(databasepath); 77 76 78 77 if (connection == null) { 79 78 logger.error("sql connection is null. database path="+databasepath); … … 82 81 83 82 try{ 84 connection.setAutoCommit(true); 85 //by passing the two arguments, the ResultSet returned from executeQuery is updatable 86 statement = connection.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE); 87 if (statement == null) { 88 logger.error("statement is null"); 89 return false; 90 } 91 92 } 83 connection.setAutoCommit(true); 84 } 93 85 catch(SQLException sqle){ 94 86 logger.debug("Database Error occured when creating a statement object",sqle); … … 103 95 ResultSet rs = null; 104 96 try{ 105 106 if (statement == null){ 107 logger.info("the database hasn't been correct yet"); 108 return new ArrayList(); 109 } 110 111 rs = statement.executeQuery(query_statement); 97 //by passing the two arguments, the ResultSet returned from executeQuery is updatable 98 Statement statement = connection.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE); 99 rs = statement.executeQuery(query_statement); 112 100 ResultSetMetaData rsmd = rs.getMetaData(); 113 101 int numOfColumns = rsmd.getColumnCount(); … … 119 107 results.add(arow); 120 108 } 121 122 rs.close(); 123 109 statement.close(); 124 110 } 125 111 catch(SQLException sqle){ … … 140 126 public synchronized ResultSet queryResultSet(String stat){ 141 127 ResultSet rs = null; 128 //by passing the two arguments, the ResultSet returned from executeQuery is updatable 129 142 130 try{ 131 Statement statement = connection.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE); 143 132 if (statement == null){ 144 133 logger.info("Null sql statement provided."); … … 165 154 public synchronized boolean execute(String stat) { 166 155 boolean rs; 156 167 157 try{ 158 Statement statement = connection.createStatement(); 168 159 if (statement == null){ 169 160 logger.info("statement is null."); … … 173 164 rs = statement.execute(stat); 174 165 statement.close(); 175 // connection.commit(); 176 } 166 } 177 167 catch(SQLException sqle){ 178 168 logger.debug("Database Error occured when execute query " + stat, sqle); … … 190 180 public synchronized boolean executeUpdate(String stat) { 191 181 int rs; 192 try{ 182 try{ 183 Statement statement = connection.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE); 193 184 if (statement == null){ 194 185 logger.info("statement is null."); … … 199 190 rs = statement.executeUpdate(stat); 200 191 statement.close(); 201 // connection.commit();202 192 logger.debug("sql stat="+stat+ " result="+rs); 203 193 } … … 218 208 */ 219 209 public void check4Table(String stat) throws SQLException { 220 statement.executeQuery(stat); 210 Statement statement = connection.createStatement(); 211 statement.executeQuery(stat); 221 212 statement.close(); 222 213 } … … 224 215 public void closeConnection(String databasepath){ 225 216 try{ 226 statement.close(); 227 connection.close(); 228 sqlServer.disconnect(databasepath); 217 if(connection != null){ 218 connection.close(); 219 connection = null; 220 sqlServer.disconnect(databasepath); 221 } 229 222 } 230 223 catch(SQLException sqle){
Note:
See TracChangeset
for help on using the changeset viewer.