你可以把sql改成 select count(rowid) rowcount, test.* from test where no = ? 不然的话你只有用游标去获得行数
Get a record count with the SQL Statement Statement s = con.createStatement(); ResultSet r = s.executeQuery("SELECT COUNT(*) AS rowcount FROM MyTable"); r.next(); int ResultCount = r.getInt("rowcount") ; r.close() ; JDBC 2.0 provides a way to retrieve a rowcount from a ResultSet without having to scan through all the rows or issue a separate SELECT COUNT(*). Statement s = conn.createStatement( ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY); ResultSet r = s.executeQuery("SELECT * FROM employee WHERE id_emp LIKE '1%'"); r.last(); count = r.getRow(); r.beforeFirst();
除了用把游标移动到最后取行号方法外。 有方法直接可以调吗?我找了好久找不到。 另外问一下, PreparedStatement stmt = con.prepareStatement("Select * from test where no = ?"); stmt.setString(1,"1"); 对于预处理,我在set后,怎样才能取得设好值(不含有问号的)后的SQL文。
select count(rowid) rowcount, test.* from test where no = ?
不然的话你只有用游标去获得行数
Statement s = con.createStatement();
ResultSet r = s.executeQuery("SELECT COUNT(*) AS rowcount FROM MyTable");
r.next();
int ResultCount = r.getInt("rowcount") ;
r.close() ;
JDBC 2.0 provides a way to retrieve a rowcount from a ResultSet without having to scan through all the rows or issue a separate SELECT COUNT(*). Statement s =
conn.createStatement( ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_READ_ONLY);
ResultSet r =
s.executeQuery("SELECT * FROM employee WHERE id_emp LIKE '1%'");
r.last();
count = r.getRow();
r.beforeFirst();
有方法直接可以调吗?我找了好久找不到。
另外问一下,
PreparedStatement stmt = con.prepareStatement("Select * from test where no = ?");
stmt.setString(1,"1");
对于预处理,我在set后,怎样才能取得设好值(不含有问号的)后的SQL文。
另外你想得到设好值的sql,需要手动通过程序去获取