在java中怎样用resultset方法把查询的表的所有值都显示出来
展开全部
首先确定你是什么库啊,得有数据库驱动
例mysql
Class.forName("com.mysql.jdbc.Driver");
Connection con = (Connection) DriverManager.getConnection(url, name,
pwd);
con.setAutoCommit(false);
Connection conn = null;
ResultSet rs;
try {
conn = getConnect(url,name,password);
String sql="select * from table ";
PreparedStatement ps = conn.prepareStatement(sql);
rs = ps.executeQuery(sql);
while(rs.next()){
//rs.getString(1);根据类型取值
}
例mysql
Class.forName("com.mysql.jdbc.Driver");
Connection con = (Connection) DriverManager.getConnection(url, name,
pwd);
con.setAutoCommit(false);
Connection conn = null;
ResultSet rs;
try {
conn = getConnect(url,name,password);
String sql="select * from table ";
PreparedStatement ps = conn.prepareStatement(sql);
rs = ps.executeQuery(sql);
while(rs.next()){
//rs.getString(1);根据类型取值
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询