java+JDBC小项目《学生管理系统》源码带注解
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
Java+javabean+JDBC学生管理系统
一、项目结构
本项目是使用javabean和jdbc做的,这个包是实体包
这个是菜单包,源码不会再发这些,自己写就好了。
二、项目运行结果
三、源码
废话不多说,直接上源码:
这两个是关键源码,是负责登录和学生信息操作的逻
辑类:
public class AdminDaoImpl extends DBHelper implements AdminDao { Admin admin = null;
/**
* 登录
*/
@SuppressWarnings("resource")
@Override
public Admin login(String name) {
String sql = "select * from admin where username=?";
Object[] param = {name};
Object obj = this.excute(sql, param);
ResultSet rs = (ResultSet) obj;
try {
while (rs.next()) {
admin = new Admin();
String username = rs.getString("username");
String password = rs.getString("password");
admin.setUsername(username);
admin.setPassword(password);
}
} catch (SQLException e) {
System.out.println("未找到此name");
}
return admin;
}
}
public class StudentDaoImpl extends DBHelper implements StudentDao {
Student stu = null;
List
@SuppressWarnings("resource")
@Override
public Student getInfoByid(int id) {
String sql = "select * from student where id=?";
Object[] param = { id };
Object obj = this.excute(sql, param);
ResultSet rs = (ResultSet) obj;
stu = new Student();
try {
while (rs.next()) {
stu.setId(rs.getInt("id"));
stu.setName(rs.getString("name"));
stu.setAge(rs.getInt("age"));
stu.setGender(rs.getString("gender"));
stu.setGrade(rs.getString("grade"));
stu.setPhone(rs.getLong("phone"));
stu.setEmail(rs.getString("email"));
stu.setAddress(rs.getString("address"));
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
this.closeAll();
}
return stu;
}
@SuppressWarnings("resource")
@Override
public List
String sql = "select * from student";
Object obj = this.excute(sql, null);
ResultSet rs = (ResultSet) obj;
list = new ArrayList
try {
while (rs.next()) {
stu = new Student();
stu.setId(rs.getInt("id"));
stu.setName(rs.getString("name"));
stu.setAge(rs.getInt("age"));
stu.setGender(rs.getString("gender"));
stu.setGrade(rs.getString("grade"));
stu.setPhone(rs.getLong("phone"));
stu.setEmail(rs.getString("email"));
stu.setAddress(rs.getString("address"));
list.add(stu);
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
this.closeAll();
}
return list;
}
@SuppressWarnings("resource")
@Override
public String getNameById(int id) {
String name = null;
String sql = "select name from student where id=?";
Object[] param = { id };
Object obj = this.excute(sql, param);
ResultSet rs = (ResultSet) obj;
try {
while (rs.next()) {
name = rs.getString("name");
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
this.closeAll();
}
return name;
}
@SuppressWarnings("resource")
@Override
public int getidByIntput(int id) {
int num = 0;
String sql = "select id from student where id=?";
Object[] param = { id };
Object obj = this.excute(sql, param);
ResultSet rs = (ResultSet) obj;
try {
while (rs.next()) {
num = rs.getInt("id");
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
this.closeAll();
}