Java+javabean+JDBC学生管理系统
一、项目结构
本项目是使用javabean和jdbc做的,这个包是实体包
这个是菜单包,源码不会再发这些,自己写就好了。
二、项目运行结果
三、源码
废话不多说,直接上源码:
这两个是关键源码,是负责登录和学生信息操作的逻
辑类:
public class AdminDaoImpl extends DBHelper implements AdminDao {
Admin admin = null;
/** * 登录 */
@SuppressWarnings(\) @Override
public Admin login(String name) {
String sql = \; Object[] param = {name};
Object obj = this.excute(sql, param); ResultSet rs = (ResultSet) obj; try {
while (rs.next()) {
admin = new Admin();
String username = rs.getString(\); String password = rs.getString(\); 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(\) @Override
public Student getInfoByid(int id) {
String sql = \;
}
Object[] param = { id };
Object obj = this.excute(sql, param); ResultSet rs = (ResultSet) obj; stu = new Student(); try {
while (rs.next()) {
stu.setId(rs.getInt(\));
stu.setName(rs.getString(\)); stu.setAge(rs.getInt(\));
stu.setGender(rs.getString(\)); stu.setGrade(rs.getString(\)); stu.setPhone(rs.getLong(\)); stu.setEmail(rs.getString(\));
stu.setAddress(rs.getString(\)); }
} catch (SQLException e) { e.printStackTrace(); } finally {
this.closeAll(); }
return stu;
@SuppressWarnings(\) @Override
public List
String sql = \; Object obj = this.excute(sql, null); ResultSet rs = (ResultSet) obj; list = new ArrayList
while (rs.next()) {
stu = new Student();
stu.setId(rs.getInt(\));
stu.setName(rs.getString(\)); stu.setAge(rs.getInt(\));
stu.setGender(rs.getString(\)); stu.setGrade(rs.getString(\)); stu.setPhone(rs.getLong(\)); stu.setEmail(rs.getString(\));
stu.setAddress(rs.getString(\)); list.add(stu); }
} catch (SQLException e) {
}
e.printStackTrace(); } finally {
this.closeAll(); }
return list;
@SuppressWarnings(\) @Override
public String getNameById(int id) { String name = null;
String sql = \; Object[] param = { id };
Object obj = this.excute(sql, param); ResultSet rs = (ResultSet) obj; try {
while (rs.next()) {
name = rs.getString(\); }
} catch (SQLException e) { e.printStackTrace(); } finally {
this.closeAll(); }
return name; }
@SuppressWarnings(\) @Override
public int getidByIntput(int id) { int num = 0;
String sql = \; Object[] param = { id };
Object obj = this.excute(sql, param); ResultSet rs = (ResultSet) obj; try {
while (rs.next()) {
num = rs.getInt(\); }
} catch (SQLException e) { e.printStackTrace(); } finally {
this.closeAll(); }