简体   繁体   中英

How to get data from a ResultSet without explicitly

I'm making a very simple application to display the contents of a database table on a webpage and so I'd like to loop through a ResultSet and stick the contents of each cell between <td> tags, etc..

Problem is that the tables can be quite large and I don't want to use the explicit getString() , getInt() , getXXX() methods. Instead, it'd be nicer to use the ResultSetMetaData method getColumnType() as a parameter to a more generic ResultSet getData(<columName>, <type>) method, but there doesn't seem to be one.

Is this possible? Am I going about this the wrong way, or am I way off base?

There is a getObject() method, but you're still going to have to cast the resulting object unless they're all strings and ints which need no special formatting. In which case you just check it for null and call toString() if it's valid.

http://docs.oracle.com/javase/1.4.2/docs/api/java/sql/ResultSet.html#getObject(int )

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM