You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Charl Gerber <ch...@yahoo.com> on 2006/12/11 10:23:49 UTC

DBUtils BeanListHandler

Hi,

Is there any special conditions your Bean has to comply to when using the default BeanListHandler? I have a class:

public class KeyValuePair
{

    private String _key;
    private String _value;

    public KeyValuePair(String key, String value)
    {
        _key   = key;
        _value = value;
    }


etc, with all the proper getters & setters. I then create this DBUtil code:

List results = (List)runner.query("SELECT someField as key,anotherField as value FROM myTable", new BeanListHandler(KeyValuePair.class));

(Simplified SQL)

It just gives me this exception with no further explanation:

java.sql.SQLException: Cannot create com.caes.sonora.util.KeyValuePair: com.caes.sonora.util.KeyValuePair Query: SELECT SONORAFIELDS.FIELDNAME as key,SONORAFIELDS.DEFAULTNAME as value FROM SONORAFIELDS,SONORACOLUMNS WHERE  SONORACOLUMNS.TABLEID=? AND SONORAFIELDS.ENUMERATION=1 AND   SONORAFIELDS.FIELDNAME=SONORACOLUMNS.FIELDNAME ORDER BY DEFAULTNAME ASC Parameters: [81]
    at org.apache.commons.dbutils.QueryRunner.rethrow(QueryRunner.java:359)
    at org.apache.commons.dbutils.QueryRunner.query(QueryRunner.java:240)
    at org.apache.commons.dbutils.QueryRunner.query(QueryRunner.java:309)
    at org.apache.commons.dbutils.QueryRunner.query(QueryRunner.java:285)
    at com.caes.struts.action.routing.CreateChoiceInitAction.getEnumerationFields(Unknown Source)
    at com.caes.struts.action.routing.CreateChoiceInitAction.getFields(Unknown Source)
    at com.caes.struts.action.routing.CreateValueInitAction.execute(Unknown Source)
    at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:419)
    at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:224)
    at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1194)
    at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:414)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:740)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
    at com.ibm.ws.webcontainer.servlet.StrictServletInstance.doService(StrictServletInstance.java:110)
    at com.ibm.ws.webcontainer.servlet.StrictLifecycleServlet._service(StrictLifecycleServlet.java:174)
    at com.ibm.ws.webcontainer.servlet.IdleServletState.service(StrictLifecycleServlet.java:313)
    at com.ibm.ws.webcontainer.servlet.StrictLifecycleServlet.service(StrictLifecycleServlet.java:116)
    at com.ibm.ws.webcontainer.servlet.ServletInstance.service(ServletInstance.java:283)
    at com.ibm.ws.webcontainer.servlet.ValidServletReferenceState.dispatch(ValidServletReferenceState.java:42)
    at com.ibm.ws.webcontainer.servlet.ServletInstanceReference.dispatch(ServletInstanceReference.java:40)
    at com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.handleWebAppDispatch(WebAppRequestDispatcher.java:1018)
    at com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.dispatch(WebAppRequestDispatcher.java:529)
    at com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.forward(WebAppRequestDispatcher.java:208)
    at com.ibm.ws.webcontainer.srt.WebAppInvoker.doForward(WebAppInvoker.java:134)
    at com.ibm.ws.webcontainer.srt.WebAppInvoker.handleInvocationHook(WebAppInvoker.java:321)
    at com.ibm.ws.webcontainer.cache.invocation.CachedInvocation.handleInvocation(CachedInvocation.java:71)
    at com.ibm.ws.webcontainer.srp.ServletRequestProcessor.dispatchByURI(ServletRequestProcessor.java:246)
    at com.ibm.ws.webcontainer.oselistener.OSEListenerDispatcher.service(OSEListener.java:334)
    at com.ibm.ws.webcontainer.http.HttpConnection.handleRequest(HttpConnection.java:56)
    at com.ibm.ws.http.HttpConnection.readAndHandleRequest(HttpConnection.java:652)
    at com.ibm.ws.http.HttpConnection.run(HttpConnection.java:458)
    at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:936)


My guess is my class has to implement a contructor that takes the ResultSet or something like that?

Thanks!

Charl




Send instant messages to your online friends http://uk.messenger.yahoo.com 

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


RE: DBUtils BeanListHandler

Posted by Tahir Akhtar <ta...@spectrum-tech.com>.
I would say you need to implement a no-args constructor and expose the bean
attributes as JavaBean getter/setter. Just a guess :)

-----Original Message-----
From: Charl Gerber [mailto:charlgerber@yahoo.com] 
Sent: Monday, December 11, 2006 2:24 PM
To: commons-user@jakarta.apache.org
Subject: DBUtils BeanListHandler

Hi,

Is there any special conditions your Bean has to comply to when using the
default BeanListHandler? I have a class:

public class KeyValuePair
{

    private String _key;
    private String _value;

    public KeyValuePair(String key, String value)
    {
        _key   = key;
        _value = value;
    }


etc, with all the proper getters & setters. I then create this DBUtil code:

List results = (List)runner.query("SELECT someField as key,anotherField as
value FROM myTable", new BeanListHandler(KeyValuePair.class));

(Simplified SQL)

It just gives me this exception with no further explanation:

java.sql.SQLException: Cannot create com.caes.sonora.util.KeyValuePair:
com.caes.sonora.util.KeyValuePair Query: SELECT SONORAFIELDS.FIELDNAME as
key,SONORAFIELDS.DEFAULTNAME as value FROM SONORAFIELDS,SONORACOLUMNS WHERE
SONORACOLUMNS.TABLEID=? AND SONORAFIELDS.ENUMERATION=1 AND
SONORAFIELDS.FIELDNAME=SONORACOLUMNS.FIELDNAME ORDER BY DEFAULTNAME ASC
Parameters: [81]
    at org.apache.commons.dbutils.QueryRunner.rethrow(QueryRunner.java:359)
    at org.apache.commons.dbutils.QueryRunner.query(QueryRunner.java:240)
    at org.apache.commons.dbutils.QueryRunner.query(QueryRunner.java:309)
    at org.apache.commons.dbutils.QueryRunner.query(QueryRunner.java:285)
    at
com.caes.struts.action.routing.CreateChoiceInitAction.getEnumerationFields(U
nknown Source)
    at
com.caes.struts.action.routing.CreateChoiceInitAction.getFields(Unknown
Source)
    at com.caes.struts.action.routing.CreateValueInitAction.execute(Unknown
Source)
    at
org.apache.struts.action.RequestProcessor.processActionPerform(RequestProces
sor.java:419)
    at
org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:224)
    at
org.apache.struts.action.ActionServlet.process(ActionServlet.java:1194)
    at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:414)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:740)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
    at
com.ibm.ws.webcontainer.servlet.StrictServletInstance.doService(StrictServle
tInstance.java:110)
    at
com.ibm.ws.webcontainer.servlet.StrictLifecycleServlet._service(StrictLifecy
cleServlet.java:174)
    at
com.ibm.ws.webcontainer.servlet.IdleServletState.service(StrictLifecycleServ
let.java:313)
    at
com.ibm.ws.webcontainer.servlet.StrictLifecycleServlet.service(StrictLifecyc
leServlet.java:116)
    at
com.ibm.ws.webcontainer.servlet.ServletInstance.service(ServletInstance.java
:283)
    at
com.ibm.ws.webcontainer.servlet.ValidServletReferenceState.dispatch(ValidSer
vletReferenceState.java:42)
    at
com.ibm.ws.webcontainer.servlet.ServletInstanceReference.dispatch(ServletIns
tanceReference.java:40)
    at
com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.handleWebAppDispatch(
WebAppRequestDispatcher.java:1018)
    at
com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.dispatch(WebAppReques
tDispatcher.java:529)
    at
com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.forward(WebAppRequest
Dispatcher.java:208)
    at
com.ibm.ws.webcontainer.srt.WebAppInvoker.doForward(WebAppInvoker.java:134)
    at
com.ibm.ws.webcontainer.srt.WebAppInvoker.handleInvocationHook(WebAppInvoker
.java:321)
    at
com.ibm.ws.webcontainer.cache.invocation.CachedInvocation.handleInvocation(C
achedInvocation.java:71)
    at
com.ibm.ws.webcontainer.srp.ServletRequestProcessor.dispatchByURI(ServletReq
uestProcessor.java:246)
    at
com.ibm.ws.webcontainer.oselistener.OSEListenerDispatcher.service(OSEListene
r.java:334)
    at
com.ibm.ws.webcontainer.http.HttpConnection.handleRequest(HttpConnection.jav
a:56)
    at
com.ibm.ws.http.HttpConnection.readAndHandleRequest(HttpConnection.java:652)
    at com.ibm.ws.http.HttpConnection.run(HttpConnection.java:458)
    at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:936)


My guess is my class has to implement a contructor that takes the ResultSet
or something like that?

Thanks!

Charl




Send instant messages to your online friends http://uk.messenger.yahoo.com 

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




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