aspose file tools*
The moose likes Servlets and the fly likes Return multiple fields aas 1 object Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Return multiple fields aas 1 object" Watch "Return multiple fields aas 1 object" New topic
Author

Return multiple fields aas 1 object

Shuaib Gill
Ranch Hand

Joined: May 29, 2001
Posts: 62
I have a query which has 5 fields after the select statement. Each of these fields are going to make one row in the query result.
So for example I may have fields
first last age occupation empid
Now each of these fields will have corresponding getXXX() and setXXX() in the JavaBean.
I want to return 1 object which holds all 5 fields. So when I return the one object, I'll get "first last age occupation empid"
not just first or last or age, etc.
So let's say for example I have this data
Joe Schmoe 22 programmer 112
Ann Lann 44 manager 113
Some Name 36 president 114
Now I want to return an object which contains all 5 fields. If I say in a Bean
getObject()
{
return row;
}
the row should return all 5 fields, not just one field. return row from the above getObject() will be
Ann Lann 44 manager 113 (it returns all the 5 fields)
Can someone help me implement this in a Java Bean? Do I need a constructor in my bean?
Please help

programmer77
DAYANAND BURAMSHETTY
Ranch Hand

Joined: Aug 06, 2001
Posts: 34
No need the constructor......

//This is normal bean or (accessor class)
public class Emp{
private long empId=0;
private String empName=null;
private String empDesg=null;
public void setEmpId(long empId){
this.empId=empId;
}
public void setEmpName(String empName){
this.empName=empName;
}
public void setEmpDesg(String empDesg){
this.empDesg=empDesg;
}
public long getEmpId(){
return this.empId;
}
public String getEmpName(){
return this.empName;
}
pulbic String getEmpDesg(){
return this.empDesg;
}
}
//This is Entity or session ....class
class EmpClass....{
//This is main function for getting the only one specified row
public Emp getObject(long empId) throws FinderException {
Connection dbConnection=null;
Statement st=null;
ResultSet rs=null;
String strQry=null;
Emp empTb=null;
try{
dbConnection = getConnection();
strQry = " SELECT EMPID,EMPNAME,EMPDESG "+
" FROM EMPTB WHERE USERID = "+empId;
st = dbConnection.createStatement();
rs = st.executeQuery(strQry);
if(!rs.next()){
throw new FinderException("RECORD IS NOT FOUND INTHE TABLE");
}else{
empTb = new Emp();
empTb.setEmpId(rs.getString(1));
empTb.setEmpName(rs.getString(2));
empTb.setEmpDesg(rs.getString(3));
return empTb;
}
}catch(Exception e){
throw new FinderException(e.getMessage());
}finally{
..
rs.close();
st.close();
dbConnection.close();
}
}
}//End class


Dil se....,<BR>Dayanand<BR>0065-8839071(off)<BR>0065-7547034(Res0
DAYANAND BURAMSHETTY
Ranch Hand

Joined: Aug 06, 2001
Posts: 34
Originally posted by DAYANAND BURAMSHETTY:
No need the constructor......

//This is normal bean or (accessor class)
public class Emp{
private long empId=0;
private String empName=null;
private String empDesg=null;
public void setEmpId(long empId){
this.empId=empId;
}
public void setEmpName(String empName){
this.empName=empName;
}
public void setEmpDesg(String empDesg){
this.empDesg=empDesg;
}
public long getEmpId(){
return this.empId;
}
public String getEmpName(){
return this.empName;
}
pulbic String getEmpDesg(){
return this.empDesg;
}
}
//This is Entity or session ....class
class EmpClass....{
//This is main function for getting the only one specified row
public Emp getObject(long empId) throws FinderException {
Connection dbConnection=null;
Statement st=null;
ResultSet rs=null;
String strQry=null;
Emp empTb=null;
try{
dbConnection = getConnection();
strQry = " SELECT EMPID,EMPNAME,EMPDESG "+
" FROM EMPTB WHERE EMPID= "+empId;
st = dbConnection.createStatement();
rs = st.executeQuery(strQry);
if(!rs.next()){
throw new FinderException("RECORD IS NOT FOUND INTHE TABLE");
}else{
empTb = new Emp();
empTb.setEmpId(rs.getString(1));
empTb.setEmpName(rs.getString(2));
empTb.setEmpDesg(rs.getString(3));
return empTb;
}
}catch(Exception e){
throw new FinderException(e.getMessage());
}finally{
..
rs.close();
st.close();
dbConnection.close();
}
}
}//End class

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Return multiple fields aas 1 object