Changeset 16883 for greenstone3
- Timestamp:
- 2008-08-18T16:20:25+12:00 (16 years ago)
- Location:
- greenstone3/trunk/src/java/org/greenstone/gsdl3/sql
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
greenstone3/trunk/src/java/org/greenstone/gsdl3/sql/DatabaseFactory.java
r16652 r16883 36 36 return server; 37 37 } catch (Exception e) { 38 logger. info("Couldn't load the database server "+ fullName);38 logger.debug("Couldn't load the database server "+ fullName); 39 39 } 40 40 … … 57 57 catch (Exception e2) { 58 58 // failed again, give up 59 logger. info("Couldn't load the sql statement "+ sqlstate);59 logger.debug("Couldn't load the sql statement "+ sqlstate); 60 60 } 61 61 } … … 97 97 catch (Exception e2) { 98 98 // failed again, give up 99 logger. info("Couldn't load the sql statement "+ sqlstate);99 logger.debug("Couldn't load the sql statement "+ sqlstate); 100 100 } 101 101 } 102 102 } 103 103 } catch (Exception e) { 104 logger. info("Couldn't load the database wrapper "+ fullName);104 logger.debug("Couldn't load the database wrapper "+ fullName); 105 105 } 106 106 -
greenstone3/trunk/src/java/org/greenstone/gsdl3/sql/MetadataDBWrapper.java
r15081 r16883 2 2 3 3 import java.util.ArrayList; 4 5 import java.sql.ResultSet; 6 import java.sql.SQLException; 7 4 8 import org.greenstone.gsdl3.util.DBInfo; 5 9 import org.greenstone.gsdl3.sql.SQLServer; … … 15 19 public boolean openConnection(String databasepath); 16 20 21 public boolean openAndCreateConnection(String databasepath); 22 17 23 //return a list of rows 18 24 public ArrayList executeQuery(String query_statement); 25 26 public ResultSet queryResultSet(String query_statement); 27 28 public boolean execute(String stat); 29 30 public boolean executeUpdate(String stat); 31 32 public void check4Table(String stat) throws SQLException; 19 33 20 34 public void closeConnection(String databasepath); -
greenstone3/trunk/src/java/org/greenstone/gsdl3/sql/derby/DerbyDBWrapper.java
r16630 r16883 14 14 import java.util.HashMap; 15 15 import java.util.Iterator; 16 16 17 17 18 import org.greenstone.gsdl3.util.DBInfo; … … 66 67 } 67 68 catch(SQLException sqle){ 68 logger. error("Database Error occured when creating a statement object",sqle);69 logger.debug("Database Error occured when creating a statement object",sqle); 69 70 return false; 70 71 } … … 72 73 } 73 74 74 //return a list of rows array->hashmap 75 public boolean openAndCreateConnection(String databasepath){ 76 connection = sqlServer.connectAndCreate(databasepath); 77 78 if (connection == null) { 79 logger.error("sql connection is null. database path="+databasepath); 80 return false; 81 } 82 83 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 } 93 catch(SQLException sqle){ 94 logger.debug("Database Error occured when creating a statement object",sqle); 95 return false; 96 } 97 return true; 98 } 99 75 100 public synchronized ArrayList executeQuery(String query_statement){ 76 101 //the database hasn't been correct yet … … 89 114 HashMap arow = new HashMap(); 90 115 for(int i = 1; i <= numOfColumns ; i++){ 91 arow.put(rsmd.getColumnName(i).toLowerCase(), rs.getObject(i));116 arow.put(rsmd.getColumnName(i).toLowerCase(), rs.getObject(i)); 92 117 } 93 118 results.add(arow); … … 95 120 } 96 121 catch(SQLException sqle){ 97 logger. error("Database Error occured when executeQuery " + query_statement,sqle);122 logger.debug("Database Error occured when executeQuery " + query_statement,sqle); 98 123 return results; 99 124 } 125 catch(Exception e){ 126 logger.debug(e); 127 return null; 128 } 100 129 return results; 101 130 } 102 103 /** check for the existence of a table**/ 104 public boolean check4Table (String check_table) { 105 try { 106 statement.execute(check_table); 107 } catch (SQLException sqle) { 108 String theError = (sqle).getSQLState(); 109 if (theError.equals("42X05")) // Table does not exist 110 { 111 return false; 112 } 113 else{ 114 return true; 115 } 116 } 117 // System.out.println("Just got the warning - table exists OK "); 118 return true; 119 } 131 /** 132 * Same as executeQuery except the return type is ResultSet 133 * @param stat 134 * @return ResultSet of querying the statement 'stat' 135 */ 136 public synchronized ResultSet queryResultSet(String stat){ 137 ResultSet rs = null; 138 try{ 139 if (statement == null){ 140 logger.info("Null sql statement provided."); 141 return null; 142 } 143 logger.debug(stat); 144 rs = statement.executeQuery(stat); 145 146 logger.info("sql stat="+stat+ " result="+rs); 147 } 148 catch(SQLException sqle){ 149 logger.info("Database Error occured when execute query " + stat, sqle); 150 return null; 151 } 152 catch(Exception e){ 153 logger.info("Exception="+e); 154 return null; 155 } 156 logger.debug(" result="+rs); 157 return rs; 158 } 159 /** 160 * Used by create (table) 161 */ 162 public synchronized boolean execute(String stat) { 163 boolean rs; 164 try{ 165 if (statement == null){ 166 logger.info("statement is null."); 167 return false; 168 } 169 170 rs = statement.execute(stat); 171 // connection.commit(); 172 } 173 catch(SQLException sqle){ 174 logger.debug("Database Error occured when execute query " + stat, sqle); 175 return false; 176 } 177 catch(Exception e){ 178 logger.debug(e); 179 return false; 180 } 181 return rs; 182 } 183 /** 184 * Used by insert, update, and delete 185 */ 186 public synchronized boolean executeUpdate(String stat) { 187 int rs; 188 try{ 189 if (statement == null){ 190 logger.info("statement is null."); 191 return false; 192 } 193 194 //either the row count of INSERT, UPDATE OR DELETE statement, or 0 if the statement returns nothing 195 rs = statement.executeUpdate(stat); 196 // connection.commit(); 197 logger.info("sql stat="+stat+ " result="+rs); 198 } 199 catch(SQLException sqle){ 200 logger.info("Database Error occured when execute query " + stat, sqle); 201 return false; 202 } 203 catch(Exception e){ 204 logger.info("Exception="+e); 205 return false; 206 } 207 logger.info(" result="+rs); 208 return (rs==-1)? false : true; 209 } 210 /** 211 * Used by checking the existence of table 212 * Same as the method 'execute' except throws SQLException 213 */ 214 public void check4Table(String stat) throws SQLException { 215 statement.executeQuery(stat); 216 } 120 217 121 218 public void closeConnection(String databasepath){
Note:
See TracChangeset
for help on using the changeset viewer.