aspose file tools*
The moose likes JDBC and the fly likes why cannot get the value in string!!! 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 » Databases » JDBC
Bookmark "why cannot get the value in string!!!" Watch "why cannot get the value in string!!!" New topic
Author

why cannot get the value in string!!!

Anthony Levis
Greenhorn

Joined: Dec 15, 2004
Posts: 10
the source code below is the method that i use to retrieve the data from the database...i have success retrieve the data but the value i get is no the value in database but just [Ljava.lang.object;@1855af5. actually the value in my database is JCX1234. how to solve this problem.how to change it to a string value.
can anyone help me.
10s.....


public void GetData(DefaultComboBoxModel cmodel) {

ResultSet rs = stmt.executeQuery("SELECT Bus_No FROM BusInfo");
//get metadata
ResultSetMetaData md = rs.getMetaData();
int colcount = md.getColumnCount();

Object[] data = new Object[colcount];
//extracting data

while (rs.next())
{
for (int i=1; i<=colcount; i++)
{
data[i-1] = rs.getString(i);

}
cmodel.addElement(data.toString());
//jcbbusno.addItem(data);
System.out.println(data);
}

}
Avi Abrami
Ranch Hand

Joined: Oct 11, 2000
Posts: 1135

Anthony,
If the data-type of column BUS_NO is not [VAR]CHAR, then you cannot use the "getString()" method to retrieve it (from the "ResultSet"). Since you are already using the "ResultSetMetaData" interface (in your code), perhaps you can use the relevant methods to determine the data-type of BUS_NO, and then use the appropriate "getXXX()" method to retrieve it. I suggest looking at these methods:

Good Luck,
Avi.
pascal betz
Ranch Hand

Joined: Jun 19, 2001
Posts: 547
data is an Object[]. You can not just printout an array and see the content.

- i would make data a String[] (since you retrieve Strings from the ResultSet)
- then print out data[i] in a loop and you should see the correct values.


pascal
pascal betz
Ranch Hand

Joined: Jun 19, 2001
Posts: 547
actualy i would make the data a List because then you do not need to fetcch the col count from the metadata.



and dont forget to close the Statement/ResultSet/PreparedStatement/Connection (in the finally clause).

pascal
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: why cannot get the value in string!!!