aspose file tools*
The moose likes JDBC and the fly likes why i get the incorrect data from mySQL???? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of JavaScript Promises Essentials this week in the JavaScript forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "why i get the incorrect data from mySQL???? " Watch "why i get the incorrect data from mySQL???? " New topic
Author

why i get the incorrect data from mySQL????

leo tien
Greenhorn

Joined: Nov 04, 2002
Posts: 11
I want get data from mySQL.
mySQL's table as following:
+---------+--------------------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+---------+--------------------------+------+-----+---------+-------+
| article | int(4) unsigned zerofill | | PRI | 0000 | |
| dealer | char(20) | | PRI | | |
| price | double(16,2) | | | 0.00 | |
+---------+--------------------------+------+-----+---------+-------+
my table is :
+---------+--------+-------+
| article | dealer | price |
+---------+--------+-------+
| 0001 | A | 3.45 |
| 0001 | B | 3.99 |
| 0002 | A | 10.99 |
| 0003 | B | 1.45 |
| 0003 | C | 1.69 |
| 0003 | D | 1.25 |
| 0004 | D | 19.95 |
+---------+--------+-------+
then I get the data from it ,
......
ResultSet result;
ResultSetMetaData rs;
......
while(result.next()) {
System.out.println(result.getString(
rs.getColumnName(1)));
/*this sentence can not run.
System.out.println(result.getInt(
rs.getColumnName(1)));
*/
System.out.println(result.getString(
rs.getColumnName(2)));
System.out.println(result.getDouble(
rs.getColumnName(3)));
}
......
it display:
......
Article : pppq
Dealer :
price : 3.45
......
as you see, the problem take place: the article's data isn't "pppq", why occur this error? How can I resolve it??please help ,,,thanks....
John Dunn
slicker
Ranch Hand

Joined: Jan 30, 2003
Posts: 1108
article field is an int(4) and you access with getString(rs.getColumnName(1).............
shouldn't it be getInt(rs.getColumnName(1))
or something like that?


"No one appreciates the very special genius of your conversation as the dog does."
Lu Battist
Ranch Hand

Joined: Feb 17, 2003
Posts: 104
Hi,
For debugging make it as simple as possible.
Try the following (forget the metadata for now):
......
ResultSet rs;
......
while(rs.next()) {
System.out.println(rs.getString(1));
System.out.println(rs.getString(2));
System.out.println(rs.getString(3));
}
......
Does it print okay now? If yes, the problem probably lies with the metadata usage. If still a problem, try the query directly from mysql.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: why i get the incorrect data from mySQL????