Reputation: 144
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?
Upvotes: 0
Views: 2770
Reputation: 6120
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)
Upvotes: 1