《Java程序设计》课程设计
主要功能实现:用户登录、用户信息的增加、删除、修改、查询等功能。
用户模块有用户界面,用户可以进行登录和注册,登录进入用户界面,可以对个人信息进行修改,可以更改自己的登录密码。
整体需求:
1)查询 2)添加用户信息 3)删除用户信息 4)查询详情,模糊查询 5)条件查询 6)修改
主页面:
新增功能页面实现:
删除功能:
查询功能:
dao层代码:增删改查
public class LoginDao {
public static void main(String[] args) {
}
public static boolean queryLogin(String username,String password) throws SQLException {
Statement stmt = null;
ResultSet rs = null;
String sql = "select * from tuserlogin where username=? and password=?";
Connection conn = SqlConnUtil.getConnectionUtils();
PreparedStatement ps = conn.prepareStatement(sql);
ps.setString(1, username);
ps.setString(2, password);
rs = ps.executeQuery();
if(rs.next()) {
return true;
}else {
return false;
}
}
public ResultSet query() throws Exception {
Statement stmt = null;
ResultSet rs = null;
String sql = "select * from tuserlogin";
Connection conn = SqlConnUtil.getConnectionUtils();
PreparedStatement ps = conn.prepareStatement(sql);
return ps.executeQuery();
}
//增加数据
public int insert(String id,String username,String password,String dj,String email) throws Exception {
Statement stmt = null;
ResultSet rs = null;
String sql = "insert into tuserlogin values(?,?,?,?,?)";
Connection conn = SqlConnUtil.getConnectionUtils();
PreparedStatement ps = conn.prepareStatement(sql);
ps.setString(1, id);
ps.setString(3, username);
ps.setString(2, password);
ps.setString(4, dj);
ps.setString(5, email);
return ps.executeUpdate();
}
//删除数据
public int delete(String id) throws Exception {
Statement stmt = null;
ResultSet rs = null;
String sql = "delete from tuserlogin where id=?";
Connection conn = SqlConnUtil.getConnectionUtils();
PreparedStatement ps = conn.prepareStatement(sql);
ps.setString(1, id);
return ps.executeUpdate();
}
//修改数据
public int update(String username,String password,String grade,String email, String id) throws Exception {
Statement stmt = null;
ResultSet rs = null;
String sql = "UPDATE tuserlogin SET username=?,PASSWORD=?,grade=?,email=? WHERE id=?";
Connection conn = SqlConnUtil.getConnectionUtils();
PreparedStatement ps = conn.prepareStatement(sql);
ps.setString(1, username);
ps.setString(2, password);
ps.setString(3, grade);
ps.setString(4, email);
ps.setString(5, id);
return ps.executeUpdate();
}
//查询
public ResultSet select(String neirong) throws SQLException {
Statement stmt = null;
ResultSet rs = null;
String sql = "select * from tuserlogin where id=? or username=? or password=? or email=?";
Connection conn = SqlConnUtil.getConnectionUtils();
PreparedStatement ps = conn.prepareStatement(sql);
ps.setString(1, neirong);
ps.setString(2, neirong);
ps.setString(3, neirong);
ps.setString(4, neirong);
return ps.executeQuery();
}
//grade查询
public ResultSet select1(String neirong) throws SQLException {
Statement stmt = null;
ResultSet rs = null;
String sql = "select * from tuserlogin where username=? or password=? or grade=? or email=?";
Connection conn = SqlConnUtil.getConnectionUtils();
PreparedStatement ps = conn.prepareStatement(sql);
ps.setString(1, neirong);
ps.setString(2, neirong);
ps.setString(3, neirong);
ps.setString(4, neirong);
return ps.executeQuery();
}
}
详细代码
