views:

7194

answers:

3

Shouldn't this be a pretty straightforward operation? However, I there is no size() or length() method.

+4  A: 
JeeBee
Inside the if(rs.last()) code block, wouldn't the correct method be rs.beforeFirst() instead of rs.first()? This way, you are not skipping the first record in your result set for processing in the while loop.
KG
KG - Indeed that looks right at a brief look at the code!
JeeBee
+13  A: 

ResultSet.last() followed by ResultSet.getRow() will give you the row count, but it may not be a good idea as it can mean reading the entire table over the network and throwing away the data. Do a SELECT COUNT(*) FROM ... query instead.

finnw
last() and getRow() aren't static methods in the ResultSet class.
JeeBee
For brevity's sake I always reference methods in this fashion when writing about them to others, regardless of whether they are static or not. Actually creating an instance of the object and calling the method is implied.
laz
A: 

For a detailed description of how to connect to SQLServer database from Java, Statement, PreparedStatment, CallableStatement, ResultSet objects etc. check this link: HOW TO: SQL in JAVA.

SNK111