File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JDBC and Relational Databases 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
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "why cannot get the value in string!!!" Watch "why cannot get the value in string!!!" New topic

why cannot get the value in string!!!

Anthony Levis

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 to change it to a string value.
can anyone help me.

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 (
for (int i=1; i<=colcount; i++)
data[i-1] = rs.getString(i);


Avi Abrami
Ranch Hand

Joined: Oct 11, 2000
Posts: 1141

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,
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 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).

I agree. Here's the link:
subject: why cannot get the value in string!!!
It's not a secret anymore!