时间:2021-07-01 10:21:17 帮助过:5人阅读
try {
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
String url = "jdbc:sqlserver://localhost:1433;DatabaseName=Temp";
String user = "wzf";
String password = "123456";
Connection conn = DriverManager.getConnection(url,user,password);
PreparedStatement ps = conn.prepareStatement(sql);
ResultSet rs = ps.executeQuery();
userList = new ArrayList<Users>();
while(rs.next()){
Users users = new Users();
String userName = rs.getString("USERNAME");
String passwords = rs.getString("PASSWORD");
users.setUserName(userName);
users.setPassword(passwords);
userList.add(users);
}
rs.close();
ps.close();
conn.close();
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}
JDBC连接数据库
标签:result query ext .exe try lis rest 连接数 red