commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From David Graham <grahamdavid1...@yahoo.com>
Subject Re: [DbUtils] 2 Questions
Date Fri, 19 Mar 2004 00:10:18 GMT
It's almost always best to post messages to the lists so that the entire
community benefits from the conversation.  

The example on the site doesn't account for empty ResultSets which is
probably why you're getting an error.  Note that the ArrayHandler class
implements the same functionality so you're probably better off using that
instead of writing a ResultSetHandler by hand.

I'll be updating the website in a few minutes to fix the example.

David

--- Stefan Edlich <edlich@gmx.net> wrote:
> Dear David,
> 
> thanks for your fast reply!
> I dont know if I should write this directly to you (which I do) or
> if its better directly via the whole commons userlist.
> 
> > 1.  Please send the code that calls QueryRunner including any custom
> > ResultSetHandler implementation you're using.
> I am using exacly the code on the website. I have attached it on the
> bottom
> of this email.
> It produces the error:
> java.sql.SQLException: No data is available Query: SELECT * FROM Person
> WHERE name=? Parameters: [Edlich]
> (By the way, all the predefined BeanHandlers work good.)
> 
> Kind regards
> Stefan E.
> 
> ====== ATTACHMENT ==================
> 
> public class Read2ObjectArray {
> 	
> 	static ResultSetHandler h = new ResultSetHandler() {
> 		public Object handle(ResultSet rs) throws SQLException {
> 			ResultSetMetaData meta = rs.getMetaData();
> 			int cols = meta.getColumnCount();
> 			Object[] result = new Object[cols];
> 			for (int i = 0; i < cols; i++) {
> 				result[i] = rs.getObject(i + 1);
> 			}
> 			return result;
> 		}
> 	};
> 
> 	public static void main(String[] args) throws SQLException {
> 		try {
> 			Class.forName("org.hsqldb.jdbcDriver");
> 		} catch (ClassNotFoundException e) {
> 			System.out.println("Cannot load Driver!");
> 			e.printStackTrace();
> 		}
> 		Connection con =
> 			DriverManager.getConnection(
> 				"jdbc:HSQLDB:D:/tmp/mydb/p_db",
> 				"sa",
> 				"");
> 
> 		QueryRunner run = new QueryRunner();
> 		Object[] result = (Object[]) run.query(
> 			con, "SELECT * FROM Person WHERE name=?", "Edlich", h);		
> 		DbUtils.close(con);
> 		System.out.println("Num=" + result.length); // At least only this
> 	}
> }
> 
> -- 
> <http://edlich.de> 
> <mailto: stefan@edlich.de>
> 
> Mobil: (+49) 0177-8594288 
> Home: (+49) (030) 8594288
> 
> Prof. Dr. Stefan Edlich
> Privat: Rönnestr.25, 14057 Berlin
> Job: FH-Brandenburg, FB Informatik und Medien, Postfach 2132, 14737 
> Brandenburg a.d. Havel 
> 
> --- INSTANT MESSAGING ---
> ICQ: 291631756
> JABBER: edlich@gmx.net
> 


__________________________________
Do you Yahoo!?
Yahoo! Mail - More reliable, more storage, less spam
http://mail.yahoo.com

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


Mime
View raw message