File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

why cannot get the value in string!!!

 
Anthony Levis
Greenhorn
Posts: 10
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1141
1
Java Oracle
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 547
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 547
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic