Win a copy of The Business Blockchain this week in the Cloud forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem with data types

 
Jennifer Sohl
Ranch Hand
Posts: 455
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello. I am accessing data from DB2/400 database that has fields coming in to my result set as numeric. Here is how I'm bringing them in to my result set:
public java.util.ArrayList getData() {
if (data == null) {
data = new ArrayList();
}
else {
data.clear();
}
try {
ResultSet rs = getvendinfo.executeQuery();
while (rs.next()) {
DataRecord dr = new DataRecord();

dr.setVendno(rs.getBigDecimal(1));
dr.setVendname(rs.getString(2));
dr.setPcontact(rs.getString(3));
dr.setPhoneno(rs.getBigDecimal(4));
dr.setFaxno(rs.getBigDecimal(5));
dr.setEmail(rs.getString(6));
dr.setCity(rs.getString(7));
dr.setState(rs.getString(8));

data.add(dr);
}

} catch (Exception e) {
System.out.println("It didn't work " + e);
}
return data;
}
Bringing these few fields in as BigDecimal causes me a problem in my TableModel's getValueAt() method which is as follows:
public Object getValueAt(int arg1, int arg2) {
String rt = null;
if ((arg1 > -1) && (arg1 < data.size())) {
DataRecord dr =(DataRecord)data.get(arg1);
switch (arg2){
case 0:
rt = dr.getVendno();
break;
case 1:
rt = dr.getVendname();
break;
case 2:
rt = dr.getPcontact();
break;
case 3:
rt = dr.getPhoneno();
break;
case 4:
rt = dr.getFaxno();
break;
case 5:
rt = dr.getEmail();
break;
case 6:
rt = dr.getCity();
break;
case 7:
rt = dr.getState();
}
}
return rt;
}
Since rt is a String type, it won't let me get my BigDecimal fields, and it won't let me cast.
How do I deal with this?
Just a Note: I tried getting the data as a String type, and I received a NumberFormatException when I tried to run it. I thought String was allowed?
Please be gentle, I am still a newbie, and really don't have that much of an understanding of the data types.
Please Help!!!
Thanks in advance
[This message has been edited by Jennifer Sohl (edited June 06, 2001).]
[This message has been edited by Jennifer Sohl (edited June 06, 2001).]
 
Julio Lopez
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Since your method getValueAt is returning class Object, what I would do is change rt to Object, then cast the Object to String or BigDecimal once you get it back from getValueAt.
public Object getValueAt(int arg1, int arg2) {
String rt = null;
if ((arg1 > -1) && (arg1 < data.size())) {
DataRecord dr =(DataRecord)data.get(arg1);
switch (arg2){
case 0:
rt = dr.getVendno();
break;
case 1:
rt = dr.getVendname();
break;
case 2:
rt = dr.getPcontact();
break;
case 3:
rt = dr.getPhoneno();
break;
case 4:
rt = dr.getFaxno();
break;
case 5:
rt = dr.getEmail();
break;
case 6:
rt = dr.getCity();
break;
case 7:
rt = dr.getState();
}
}
return rt;
}
Julio Lopez
M-Group Systems
[This message has been edited by Julio Lopez (edited June 06, 2001).]
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic