From commons-user-return-6995-apmail-jakarta-commons-user-archive=jakarta.apache.org@jakarta.apache.org Fri Mar 19 00:10:32 2004 Return-Path: Delivered-To: apmail-jakarta-commons-user-archive@www.apache.org Received: (qmail 76029 invoked from network); 19 Mar 2004 00:10:32 -0000 Received: from daedalus.apache.org (HELO mail.apache.org) (208.185.179.12) by minotaur-2.apache.org with SMTP; 19 Mar 2004 00:10:32 -0000 Received: (qmail 92908 invoked by uid 500); 19 Mar 2004 00:10:12 -0000 Delivered-To: apmail-jakarta-commons-user-archive@jakarta.apache.org Received: (qmail 92870 invoked by uid 500); 19 Mar 2004 00:10:12 -0000 Mailing-List: contact commons-user-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "Jakarta Commons Users List" Reply-To: "Jakarta Commons Users List" Delivered-To: mailing list commons-user@jakarta.apache.org Received: (qmail 92843 invoked from network); 19 Mar 2004 00:10:11 -0000 Received: from unknown (HELO web60802.mail.yahoo.com) (216.155.196.65) by daedalus.apache.org with SMTP; 19 Mar 2004 00:10:11 -0000 Message-ID: <20040319001018.59311.qmail@web60802.mail.yahoo.com> Received: from [24.9.52.44] by web60802.mail.yahoo.com via HTTP; Thu, 18 Mar 2004 16:10:18 PST Date: Thu, 18 Mar 2004 16:10:18 -0800 (PST) From: David Graham Subject: Re: [DbUtils] 2 Questions To: commons-user@jakarta.apache.org In-Reply-To: <1143.1079653880@www67.gmx.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N X-Spam-Rating: minotaur-2.apache.org 1.6.2 0/1000/N 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 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 > } > } > > -- > > > > 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