int num=0;
while(rsnext){
num++;
}
systemoutprintln(num);首先确定你是什么库啊,得有数据库驱动
例mysql
ClassforName("commysqljdbcDriver");
Connection con = (Connection) DriverManagergetConnection(url, name,
pwd);
consetAutoCommit(false);
Connection conn = null;
ResultSet rs;
try {
conn = getConnect(url,name,password);
String sql="select from table ";
PreparedStatement ps = connprepareStatement(sql);
rs = psexecuteQuery(sql);
while(rsnext()){
//rsgetString(1);根据类型取值
}java获取ResultSet的行数列数
import JavasqlConnection;
import javasqlResultSet;
import javasqlSQLException;
public class ResultSetTest {
public static void main(String[] args) {
Connection con;
try {
//获取数据库连接
con = DBUtilgetConnection("69");
//设置查询语句
String sql = "select from 表名 ";
//设计结果集为可滚动
javasqlPreparedStatement pst = conprepareStatement(sql,
ResultSetTYPE_SCROLL_INSENSITIVE,ResultSetCONCUR_READ_ONLY);
javasqlResultSet rs = pstexecuteQuery();
//获取结果集的列数
Systemoutprintln(rsgetMetaData()getColumnCount());
//将结果集滚动到最后一个
rslast();
//获取结果集当前行数
Systemoutprintln(rsgetRow());
} catch (SQLException e) {
eprintStackTrace();
}
}
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)