You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by David Graham <gr...@yahoo.com> on 2004/12/21 02:59:39 UTC

Re: [dbutils] Problem with common DBUtil Bean

First, you need to alias the column names in the sql to avoid having to
use the horrible underscore in your java method names:

select index_id as indexID, document_type as documentType, date_entered as
dateEntered from MyTable

DBUtils 1.0 didn't contain very intelligent column to bean property
mapping.  Oracle's JDBC driver returns NUMBER columns as BigDecimal so
changing your indexID from a long to a BigDecimal should fix the problem. 
However, working with longs is easier so I suggest you download the latest
nightly build of DBUtils.  Since 1.0 was released we made the type mapping
a bit smarter so your long indexID should be populated correctly.

David

--- spframe live <sp...@yahoo.com> wrote:

> 
> I have 
> Table with these column name and types
> 
> INDEX_ID NUMBER,
> DOCUMENT_TYPE VARCHAR2(3),
> DATE_ENTERED DATE,
> 
> SELECT index_id, document_type, date_entered from MyTable;
> and database has required data.
>                 
> public MyBean class  { 
> 
>   public long index_ID        ;
>   public String document_Type  ;
>   public java.sql.Date date_Entered     ;
>  
>  public MyBean(){
>     super();
>  }
>  
>  public long getIndex_ID() {
>   return index_ID;
>  }
>  public void setIndex_ID(long index_ID) {
>   this.index_ID = index_ID;
>  }
>  
>  
>  
>  public java.sql.Date getDate_Entered() {
>   return this.date_Entered;
>  }
>  public void setDate_Entered(java.sql.Date date_Entered) {
>   this.date_Entered = date_Entered;
>  } 
>  
>  
>  public String getDocument_Type() {
>   return document_Type;
>  }
>  public void setDocument_Type(String document_Type) {
>   this.document_Type =  document_Type;
>  }
>  
> }
> 
> public SomeTestCalss {
>  public void someTestmethod(){
>   // some how got connetion/ result set statement this is tested ok
>   callst.execute();
>   //Casting the returned parameter, OracleTypes.CURSOR to a JDBC
> ResultSet
>   rset = (ResultSet)callst.getObject(1);
>   rset = StringTrimmedResultSet.wrap(rset);
>   SqlNullCheckedResultSet sqlncrswrap = new
> SqlNullCheckedResultSet(rset);
>     
>   sqlncrswrap.setNullDate(null) ;
>     sqlncrswrap.setNullInt(0) ;
>     sqlncrswrap.setNullString(""); 
>  
>   rset = ProxyFactory.instance().createResultSet(sqlncrswrap);
>   // Pass wrapped ResultSet to processor
> 
>    results = BasicRowProcessor.instance().toBeanList(rset,MyBean.class);
> 
>    Iterator iter = mciResults.iterator();
>    while (iter.hasNext()) {
>     MyBean mb = (MyBean) iter.next();
>     System.out.println("Index ID"+mb.getIndex_ID());
>     System.out.println("Document Type"+mb.getDocument_Type());
>     System.out.println("date_entered "+mb.getDate_Entered());
>     }
>  }
> }
>  
> 
> output looks like this 
> Index ID 0 
> Document Type MYDOCTYPE 
> Date entered null 
> 
> Why Index ID for all rows is 0 and Date entered for all rows is null
> while I can get Document Type value correctly.
> 
> 
> 		
> ---------------------------------
> Do you Yahoo!?
>  Send a seasonal email greeting and help others. Do good.



		
__________________________________ 
Do you Yahoo!? 
Yahoo! Mail - now with 250MB free storage. Learn more.
http://info.mail.yahoo.com/mail_250

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


Re: [dbutils] Problem with common DBUtil Bean

Posted by spframe live <sp...@yahoo.com>.
Right I just changed from long  to java.math.BigDecimal and for date field java.sql.Timestamp
and it worked. I will try new build soon.
Thanks for quick reply
spframe live

David Graham <gr...@yahoo.com> wrote:
First, you need to alias the column names in the sql to avoid having to
use the horrible underscore in your java method names:

select index_id as indexID, document_type as documentType, date_entered as
dateEntered from MyTable

DBUtils 1.0 didn't contain very intelligent column to bean property
mapping. Oracle's JDBC driver returns NUMBER columns as BigDecimal so
changing your indexID from a long to a BigDecimal should fix the problem. 
However, working with longs is easier so I suggest you download the latest
nightly build of DBUtils. Since 1.0 was released we made the type mapping
a bit smarter so your long indexID should be populated correctly.

David

--- spframe live wrote:

> 
> I have 
> Table with these column name and types
> 
> INDEX_ID NUMBER,
> DOCUMENT_TYPE VARCHAR2(3),
> DATE_ENTERED DATE,
> 
> SELECT index_id, document_type, date_entered from MyTable;
> and database has required data.
> 
> public MyBean class { 
> 
> public long index_ID ;
> public String document_Type ;
> public java.sql.Date date_Entered ;
> 
> public MyBean(){
> super();
> }
> 
> public long getIndex_ID() {
> return index_ID;
> }
> public void setIndex_ID(long index_ID) {
> this.index_ID = index_ID;
> }
> 
> 
> 
> public java.sql.Date getDate_Entered() {
> return this.date_Entered;
> }
> public void setDate_Entered(java.sql.Date date_Entered) {
> this.date_Entered = date_Entered;
> } 
> 
> 
> public String getDocument_Type() {
> return document_Type;
> }
> public void setDocument_Type(String document_Type) {
> this.document_Type = document_Type;
> }
> 
> }
> 
> public SomeTestCalss {
> public void someTestmethod(){
> // some how got connetion/ result set statement this is tested ok
> callst.execute();
> //Casting the returned parameter, OracleTypes.CURSOR to a JDBC
> ResultSet
> rset = (ResultSet)callst.getObject(1);
> rset = StringTrimmedResultSet.wrap(rset);
> SqlNullCheckedResultSet sqlncrswrap = new
> SqlNullCheckedResultSet(rset);
> 
> sqlncrswrap.setNullDate(null) ;
> sqlncrswrap.setNullInt(0) ;
> sqlncrswrap.setNullString(""); 
> 
> rset = ProxyFactory.instance().createResultSet(sqlncrswrap);
> // Pass wrapped ResultSet to processor
> 
> results = BasicRowProcessor.instance().toBeanList(rset,MyBean.class);
> 
> Iterator iter = mciResults.iterator();
> while (iter.hasNext()) {
> MyBean mb = (MyBean) iter.next();
> System.out.println("Index ID"+mb.getIndex_ID());
> System.out.println("Document Type"+mb.getDocument_Type());
> System.out.println("date_entered "+mb.getDate_Entered());
> }
> }
> }
> 
> 
> output looks like this 
> Index ID 0 
> Document Type MYDOCTYPE 
> Date entered null 
> 
> Why Index ID for all rows is 0 and Date entered for all rows is null
> while I can get Document Type value correctly.
> 
> 
> 
> ---------------------------------
> Do you Yahoo!?
> Send a seasonal email greeting and help others. Do good.




__________________________________ 
Do you Yahoo!? 
Yahoo! Mail - now with 250MB free storage. Learn more.
http://info.mail.yahoo.com/mail_250

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


		
---------------------------------
Do you Yahoo!?
 Take Yahoo! Mail with you! Get it on your mobile phone.