java+mysql+swing学生选课系统

代码太多了,需要源代码的加QQ:1396336863

 

下面是部分关键代码

package com.jakey.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import com.jakey.model.Course;
import com.jakey.util.StringUtil;



public class CourseDao {
	public int courseAdd(Connection con,Course course)throws Exception{
		String sql="insert into t_course value(null,?,?,?,?,0)";
		PreparedStatement  pstmt=con.prepareStatement(sql);
		pstmt.setString(1,course.getCourseName());
		pstmt.setString(2, course.getCourseTime());
		pstmt.setString(3, course.getCourseTeacher());
		pstmt.setInt(4, course.getCapacity());
		return pstmt.executeUpdate();

	}
	public ResultSet courseList(Connection con,Course course) throws SQLException{
		StringBuffer sb=new StringBuffer("select * from t_course");
		if(StringUtil.isNotEmpty(course.getCourseName())){
			sb.append(" and courseName like '%"+course.getCourseName()+"%'");
		}
		if(StringUtil.isNotEmpty(course.getCourseTime())){
			sb.append(" and courseTime like '%"+course.getCourseTime()+"%'");
		}
		if(StringUtil.isNotEmpty(course.getCourseTeacher())){
			sb.append(" and courseTeacher like '%"+course.getCourseTeacher()+"%'");
		}
PreparedStatement pstmt=con.prepareStatement(sb.toString().replaceFirst("and", "where"));
return pstmt.executeQuery();
		}
	public int courseDelete(Connection con,String courseId)throws Exception{
		String sql="delete from t_course where courseId=?";
		PreparedStatement  pstmt=con.prepareStatement(sql);
		pstmt.setString(1, courseId);
		return pstmt.executeUpdate();

	}
	public int courseModify(Connection con,Course course)throws Exception{
		String sql="update t_course set courseName=?,courseTime=?,courseTeacher=?,capacity=? where courseId=? ";
		PreparedStatement pstmt=con.prepareStatement(sql);
		pstmt.setString(1, course.getCourseName());
		pstmt.setString(2, course.getCourseTime());
		pstmt.setString(3, course.getCourseTeacher());
		pstmt.setInt(4,course.getCapacity() );
		pstmt.setInt(5, course.getCourseId());
		return pstmt.executeUpdate();
		
	}
	public ResultSet UnderFullList(Connection con,Course course) throws SQLException{
		String sql="select * from t_course where capacity>numSelected";
		PreparedStatement pstmt=con.prepareStatement(sql);
		return pstmt.executeQuery();
	}
	}


  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值