dgraham 2003/10/15 20:34:07
Modified: dbutils/src/java/org/apache/commons/dbutils
ResultSetIterator.java ResultSetIteratorV1.java
DbUtils.java
Log:
Stack traces should never get written to stderr. I've commented out those
lines and added TODO reminders in case we want to incorporate
Commons Logging later.
Revision Changes Path
1.4 +23 -15
jakarta-commons-sandbox/dbutils/src/java/org/apache/commons/dbutils/ResultSetIterator.java
Index: ResultSetIterator.java
===================================================================
RCS file:
/home/cvs/jakarta-commons-sandbox/dbutils/src/java/org/apache/commons/dbutils/ResultSetIterator.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- ResultSetIterator.java 15 Oct 2003 02:37:31 -0000 1.3
+++ ResultSetIterator.java 16 Oct 2003 03:34:07 -0000 1.4
@@ -58,7 +58,7 @@
* <http://www.apache.org/>.
*
*/
-
+
package org.apache.commons.dbutils;
import java.sql.ResultSet;
@@ -66,12 +66,15 @@
import java.util.Iterator;
/**
- * A version of result set iterator that is simpler, but needs isLast which
- * Oracle fails to offer. As such this is sidelined until Oracle adds features.
+ * A version of ResultSetIterator that is simpler, but needs isLast which
+ * Oracle fails to offer. As such this is sidelined until Oracle adds
+ * features.
+ *
+ * @author Henri Yandell
*/
class ResultSetIterator implements Iterator {
- private ResultSet rs;
+ private ResultSet rs = null;
public ResultSetIterator(ResultSet rs) {
this.rs = rs;
@@ -80,8 +83,10 @@
public boolean hasNext() {
try {
return !rs.isLast();
- } catch(SQLException sqle) {
- sqle.printStackTrace();
+
+ } catch (SQLException e) {
+ // TODO Logging?
+ //e.printStackTrace();
return false;
}
}
@@ -90,19 +95,22 @@
try {
rs.next();
return DbUtils.resultSetToArray(rs);
- } catch(SQLException sqle) {
- sqle.printStackTrace();
+
+ } catch (SQLException e) {
+ // TODO Logging?
+ //e.printStackTrace();
return null;
}
}
public void remove() {
-// throw new UnsupportedOperationException("Cannot remove from a "+
-// "java.sql.ResultSet." );
+
try {
this.rs.deleteRow();
- } catch(SQLException sqle) {
- sqle.printStackTrace();
+
+ } catch (SQLException e) {
+ // TODO Logging?
+ //e.printStackTrace();
}
}
1.4 +10 -15
jakarta-commons-sandbox/dbutils/src/java/org/apache/commons/dbutils/ResultSetIteratorV1.java
Index: ResultSetIteratorV1.java
===================================================================
RCS file:
/home/cvs/jakarta-commons-sandbox/dbutils/src/java/org/apache/commons/dbutils/ResultSetIteratorV1.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- ResultSetIteratorV1.java 15 Oct 2003 02:37:31 -0000 1.3
+++ ResultSetIteratorV1.java 16 Oct 2003 03:34:07 -0000 1.4
@@ -58,7 +58,7 @@
* <http://www.apache.org/>.
*
*/
-
+
package org.apache.commons.dbutils;
import java.sql.ResultSet;
@@ -76,7 +76,7 @@
}
public boolean hasNext() {
- if(!this.hasNextCalledLast) {
+ if (!this.hasNextCalledLast) {
this.hasNextCalledLast = true;
doNext();
}
@@ -84,7 +84,7 @@
}
public Object next() {
- if(this.val == null) {
+ if (this.val == null) {
doNext();
}
this.hasNextCalledLast = false;
@@ -95,20 +95,15 @@
try {
rs.next();
this.val = DbUtils.resultSetToArray(rs);
- } catch(SQLException sqle) {
- //sqle.printStackTrace();
+
+ } catch (SQLException sqle) {
this.val = null;
}
}
public void remove() {
- throw new UnsupportedOperationException("Cannot remove from a "+
- "java.sql.ResultSet." );
-// try {
-// this.rs.deleteRow();
-// } catch(SQLException sqle) {
-// sqle.printStackTrace();
-// }
+ throw new UnsupportedOperationException(
+ "Cannot remove from a " + "java.sql.ResultSet.");
}
}
1.34 +29 -24
jakarta-commons-sandbox/dbutils/src/java/org/apache/commons/dbutils/DbUtils.java
Index: DbUtils.java
===================================================================
RCS file:
/home/cvs/jakarta-commons-sandbox/dbutils/src/java/org/apache/commons/dbutils/DbUtils.java,v
retrieving revision 1.33
retrieving revision 1.34
diff -u -r1.33 -r1.34
--- DbUtils.java 16 Oct 2003 03:04:42 -0000 1.33
+++ DbUtils.java 16 Oct 2003 03:34:07 -0000 1.34
@@ -321,41 +321,46 @@
try {
Class.forName(name).newInstance();
return true;
-
- } catch (ClassNotFoundException cnfe) {
- cnfe.printStackTrace();
+
+ } catch (ClassNotFoundException e) {
+ // TODO Logging?
+ //e.printStackTrace();
return false;
-
- } catch (IllegalAccessException iae) {
- iae.printStackTrace();
+
+ } catch (IllegalAccessException e) {
+ // TODO Logging?
+ //e.printStackTrace();
+
// Constructor is private, OK for DriverManager contract
- return true;
-
- } catch (InstantiationException ie) {
- ie.printStackTrace();
+ return true;
+
+ } catch (InstantiationException e) {
+ // TODO Logging?
+ //e.printStackTrace();
return false;
-
- }catch(Throwable t){
+
+ } catch (Throwable t) {
return false;
}
}
/**
- * Create an Map from a ResultSet.
+ * Create a Map from a ResultSet.
* It is assumed that next() has already been called on the ResultSet.
*/
-
- public static java.util.Map resultSetToMap(ResultSet rs) throws SQLException {
- java.util.Map result = new java.util.Hashtable();
+ public static Map resultSetToMap(ResultSet rs) throws SQLException {
+ Map result = new HashMap();
ResultSetMetaData rsmd = rs.getMetaData();
- int cnt = rsmd.getColumnCount();
- for( int i = 1; i <= cnt; i++ ){
+ int cols = rsmd.getColumnCount();
+
+ for (int i = 1; i <= cols; i++) {
Object value = rs.getObject(i);
- if(!rs.wasNull()){
- result.put(rsmd.getColumnName(i),value);
+ if (!rs.wasNull()) {
+ result.put(rsmd.getColumnName(i), value);
}
}
- return result;
+
+ return result;
}
/**
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]