package dao;

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

import model.Course;

public class Couinfo {
	List<Course> list=new ArrayList<Course>();
	DbJdbc dt=new DbJdbc();
	Course cou=null;
	
	
	//1.准备从数据库遍历所有课程信息
	public void  showCouAll(String sql){
		dt.dbConn();
		try {
			dt.st=dt.conn.createStatement();
			dt.rs=dt.st.executeQuery(sql);
			ResultSet rst=dt.rs;
			while(rst.next()){
				String kc=rst.getString(1);
				String name=rst.getString(2);
				String type=rst.getString(3);
				int credit=rst.getInt(4);
				int tid=rst.getInt(5);
				Course cou=new Course(kc,name,type,credit,tid);
				list.add(cou);
			}
			
		} catch (SQLException e) {
			dt.close();
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	//2.查询课程信息
public List<Course> getAllCourse(){
	String sql="select * from course";
	showCouAll(sql);
	return list;
	
}

 //3.增加课程信息
public void couAdd(String id,String name,String type,int credit,int tid){
	String sql="insert into course value('"+id+"','"+name+"','"+type+"',"+credit+","+tid+")";
	dt.zsg(sql);
}
   

   //4、删除课程信息
   public void couDelete(String id){
	   String sql="delete from course where cid='"+id+"'";
	   dt.zsg(sql);
   }
   
   
   //5、修改课程信息
   public void couUpdate(String id,String name,String type,int credit,int tid){
	   String sql="update course set cname='"+name+"',type='"+type+"',credit="+credit+",tid="+tid+" where cid='"+id+"'";
	   dt.zsg(sql);
   }


//6、判断新增加的课程号是否已经添加
   public Course checkId(String id){
	   String sql="select * from course where cid='"+id+"'";
	   dt.dbConn();
	   try {
		dt.st=dt.conn.createStatement();
		dt.rs=dt.st.executeQuery(sql);
		ResultSet rst=dt.rs;
		while(rst.next()){
			String kc=rst.getString(1);
			String name=rst.getString(2);
			String type=rst.getString(3);
			int credit=rst.getInt(4);
			int tid=rst.getInt(5);
			 cou=new Course(kc,name,type,credit,tid);
		}
	} catch (SQLException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
	return cou;
	   
   }
   
}
最近下载更多
tmf852  LV5 2023年6月10日
Tayirjan  LV11 2023年3月23日
263648  LV7 2022年6月23日
ouyun12345  LV4 2022年5月17日
微信网友_5764743416303616  LV6 2022年4月25日
kuoluoluo  LV3 2022年4月18日
朱朱啊哈  LV16 2022年3月4日
123123123W  LV7 2022年2月28日
CCCbbbcai  LV6 2021年12月23日
3089559272  LV11 2021年12月17日
最近浏览更多
周青松5  LV2 1月15日
杨豫川  LV12 1月12日
minjing123  LV8 1月4日
颜菜菜  LV2 1月4日
Nuyoah_L 1月3日
暂无贡献等级
pangzhihui  LV12 2023年12月20日
微信网友_6786215447367680  LV4 2023年12月20日
CCCCWWWW  LV4 2023年12月11日
3320151533  LV1 2023年12月7日
2010160433  LV3 2023年11月30日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友