📄 userservice.java
字号:
package com.allanlxf.jdbc;
import java.util.Collection;
import java.util.ArrayList;
import java.sql.*;
import com.allanlxf.jdbc.util.ConnectionFactory;
import com.allanlxf.jdbc.util.JdbcUtil;
public class UserService
{
public Collection<User> findUsers()
{
Connection con = null;
PreparedStatement ps = null;
ResultSet rs = null;
Collection<User> users = new ArrayList<User>();
try
{
con = ConnectionFactory.getConnection();
String sql = "select * from user_serv";
ps = con.prepareStatement(sql);
rs = ps.executeQuery();
while(rs.next())
{
User user = new User();
user.setId(rs.getInt("id"));
user.setUserName(rs.getString("username"));
user.setPassword(rs.getString("pwd"));
user.setGender(rs.getString("gender"));
user.setProvince(rs.getString("province"));
user.setHobbies(rs.getString("hobbies"));
user.setIntroduction(rs.getString("introduction"));
users.add(user);
}
}catch(Exception e)
{
e.printStackTrace();
throw new RuntimeException(e.getMessage());
}finally
{
JdbcUtil.close(rs, ps, con);
}
return users;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -