java - getting user defined object instances from resultset -



java - getting user defined object instances from resultset -

i have coding assignment in got stuck...

i have business relationship table in need select unprocessed accounts; that's have done easy

now assignment inquire me homecoming each business relationship in accounts array; got query

so, how homecoming business relationship array(how fill in each unporcessed business relationship in resultset) accounts array homecoming defined function not allowed chnge.

is way resultset: homecoming single row contain business relationship instance?

we need utilize java 5 , not allowed implement 3rd party library

p.s

i have tried:

account business relationship = (account) rs.getobject("id");` has classcast exception

and

account business relationship = (account) rs.getobject("id",account.class); has other exception

i have read about: customized type mappings not sure after doing sugggest desired resuts

and solution involves creating customtype(in case account) on databaselevel first not allowed touch

as mentioned in other answer

please share exp.

the class cast exception getting expected because rs.getobject("id") not give object of class account. can create array (or list) of business relationship objects , populate while iterating through result set. (assuming have info of business relationship in single row of result set). allow assume business relationship class follows :

class business relationship { int id; string accounttype; string accountholdername; long accountbalance; ... ... ... }

//assuming table columns querying have these fields each row:

accountid | accounttype | accountholdername | accountbalance | ... 101 | checking | john | 100 | ...

//populating business relationship objects

business relationship [] accarray = new accarray [sizeofresultset]; int i=0; while (rs.next()){ business relationship current = new account(); current.id = rs.getint("accountid"); current.accounttype = rs.getstring("accounttype"); current.accountholdername = rs.getstring("accountholdername"); ... ... ... }

java sql jdbc resultset

Comments

Popular posts from this blog

formatting - SAS SQL Datepart function returning odd values -

c++ - Apple Mach-O Linker Error(Duplicate Symbols For Architecture armv7) -

php - Yii 2: Unable to find a class into the extension 'yii2-admin' -