src/edu/school/dao/impl/StudentDaoImpl.java
(开头部分) 5KB这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。
package edu.school.dao.impl;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import edu.school.dao.StudentDao;
import edu.school.entity.*;
import edu.school.utils.C3p0Utils;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;
import org.apache.commons.dbutils.handlers.BeanListHandler;
import org.apache.commons.dbutils.handlers.ScalarHandler;
public class StudentDaoImpl implements StudentDao {
private QueryRunner runner=new QueryRunner(C3p0Utils.getDs());
//根据学号查询
public Student queryByStuno(String stuno) {
try {//返回查询的信息
return runner.query("select * from student where stuno=?", new BeanHandler<Student>(Student.class),stuno);
} catch (SQLException e) {
throw new RuntimeException(e);//抛出运行异常
}
}
//返回查询的信息
public Student queryByStunoAndPwd(String stuno, String pwd) {
try {
return runner.query("select * from student where stuno=? and pwd=?", new BeanHandler<Student>(Student.class),stuno,pwd);
} catch (SQLException e) {
throw new RuntimeException(e);//抛出运行异常
}
}
//保存学生信息
public int save(Student student) {
try {
//执行插入sql
runner.update("insert into student(stuno,realname,pwd,createDate) values (?,?,?,?)",
student.getStuno(),student.getRealname(),student.getPwd(),student.getCreateDate());
} catch (SQLException e) {
throw new RuntimeException(e);
}
return 1;
}
public static void main(String[] args) {
StudentDaoImpl daoImpl=new StudentDaoImpl();
/*daoImpl.save();*/
}
public Student query(Integer id) {//根据id查询
try {//返回查询的信息
return runner.query("select * from student where id=?", new BeanHandler<Student>(Student.class),id);
} catch (SQLException e) {
throw new RuntimeException(e);//抛出运行异常
后面还有 100 行代码,购买后查看完整代码
24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明
AI 解读 AI
登录后可用,每次 10 算力,解读结果公开显示在下面。
还没有人解读过这个文件。