当前位置 : 主页 > 编程语言 > java >

学生项目

来源:互联网 收集:自由互联 发布时间:2021-06-28
StudentDao.java package com.jiyun.dao;import java.sql.SQLException;import java.util.List;import org.apache.commons.dbutils.QueryRunner;import org.apache.commons.dbutils.handlers.BeanHandler;import org.apache.commons.dbutils.handlers.BeanLis
StudentDao.java
package com.jiyun.dao;

import java.sql.SQLException;
import java.util.List;

import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;
import org.apache.commons.dbutils.handlers.BeanListHandler;

import com.jiyun.domain.Student;
import com.jiyun.utils.JDBCUtils;

public class StudentDao {

	private static QueryRunner qr = new QueryRunner(JDBCUtils.getDataSource());

	// 登陆验证
	public static Student checkLogin(Student stu) {
		// sql语句
		String sql = "select * from student where username=? and password=?";
		// 执行sql语句
		Student st = null;
		try {
			st = qr.query(sql, new BeanHandler
 
  (Student.class),
					stu.getUsername(), stu.getPassword());
		} catch (SQLException e) {
			e.printStackTrace();
		}

		return st;
	}

	public static List
  
    show() { // sql语句 String sql = "select * from student"; // 执行sql语句 List
   
     list = null; try { list = qr.query(sql, new BeanListHandler
    
     (Student.class)); } catch (SQLException e) { e.printStackTrace(); } return list; } public static Student checkName(String username) { // sql语句 String sql = "select * from student where username=?"; // 执行sql语句 Student stu = null; try { stu = qr.query(sql, new BeanHandler
     
      (Student.class), username); } catch (SQLException e) { e.printStackTrace(); } return stu; } public static void insert(Student stu) { // sql语句 String sql = "insert into student values(null,?,?,?,?,?)"; // 执行sql语句 try { qr.update(sql, stu.getUsername(), stu.getPassword(), stu.getAge(), stu.getSex(), stu.getPhoto()); } catch (SQLException e) { e.printStackTrace(); } } public static List
      
        searchByName(String username) { username = "%" + username + "%"; // sql语句 String sql = "select * from student where username like ?"; // 发送sql语句 List
       
         list = null; try { list = qr.query(sql, new BeanListHandler
        
         (Student.class), username); } catch (SQLException e) { e.printStackTrace(); } return list; } public static void deleteById(String id) { // sql语句 String sql = "delete from student where id=?"; // 发送sql语句 try { qr.update(sql, id); } catch (SQLException e) { e.printStackTrace(); } } public static Student selectById(String id) { // sql语句 String sql = "select * from student where id=?"; Student stu = null; try { stu = qr.query(sql, new BeanHandler
         
          (Student.class), id); } catch (SQLException e) { e.printStackTrace(); } return stu; } public static void update(Student stu) { // sql语句 String sql = "update student set username=?,password=?,age=?,sex=?,photo=? where id=?"; // 执行sql语句 try { qr.update(sql, stu.getUsername(), stu.getPassword(), stu.getAge(), stu.getSex(), stu.getPhoto(), stu.getId()); } catch (SQLException e) { e.printStackTrace(); } } }
         
        
       
      
     
    
   
  
 
网友评论