2013年9月2日星期一

java how to get Count (*) value

 This post last edited by the u011613626 on 2013-08-28 20:50:48
My code is as follows:
public int getTopicId (int Id) {
int i = 0; < br />
try {
String sql = "select count (*) from selTopic Where TopicId =?";
pst = conn.prepareStatement (sql );
pst.setInt (1, Id);
rs = pst.executeQuery ();

if (rs.next ()) {
......
}
}
catch (SQLException ex) {
ex.printStackTrace ();
}
finally {
source.closeResultSet (rs);
source.closePreparedStatement (pst);
source.closeConnection (conn);
}

return i;
}

Will ...... at what the complete , in order to obtain Count (*) value. If my idea is wrong, then how to write it ? Trouble you help me find !
------ Solution ---------------------------------------- ----
rs.getInt (1)
------ Solution --------------------------- -----------------
rs.getInteger (1)
------ For reference only ------------ ---------------------------
+1
------ For reference only - -------------------------------------
can not but standard colors, eyes looking tired . . .
------ For reference only -------------------------------------- -
sql * do not use
use count (0) will be able to get the total number of records
------ For reference only ----------------------- ----------------

write can get the total number of records ?
------ For reference only -------------------------------------- -


count (0) how to use ? Is rs.getInt (counr (0)) do ?
------ For reference only -------------------------------------- -

next note !

没有评论:

发表评论