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
posted
0
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
posted
0
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.