存
作者:互联网
package dao;
import java.sql.*;
import java.util.ArrayList;
import entity.User;
import util.DBConn;
public class UserDao {
public ArrayList<User> getAllUserInfos(){
DBConn obj =new DBConn();
Connection conn=obj.getConnection();
ArrayList<User> users=new ArrayList<>();
if (conn==null) {System.out.println("数据库出错");
return null;}
String sql="SELECT * FROM test01.tt";
try { PreparedStatement ptst = conn.prepareStatement(sql);
ResultSet rs=ptst.executeQuery();
rs.last();
rs.beforeFirst();
while(rs.next()) {
User user=new User();
user.setclas(rs.getString("class"));
user.sethref(rs.getString("tiem"));
user.settitle(rs.getString("title"));
}}
catch (SQLException e) {
e.printStackTrace();
System.out.println("SQL语句有误");
return null;
}
return users;
}
public static void main(String[] args) {
// TODO Auto-generated method stub
new UserDao().getAllUserInfos();
}
}
标签:,return,getString,rs,ArrayList,user,import 来源: https://www.cnblogs.com/hahaah/p/16275387.html