简单学生选课系统之课程基本信息


Course.java

package nuc.select.course;

public class Course {
    private String cno;
    private String cname;
    private String cteacher;
    private int ccredit;
    public String getCno(){
    	return cno;
    }
    public void setCno(String cno){
    	this.cno=cno;
    }
    public String getCname(){
    	return cname;
    }
    public void setCname(String cname){
    	this.cname=cname;
    }
    public String getCteacher(){
    	return cteacher;
    }
    public void setCteacher(String cteacher){
    	this.cteacher=cteacher;
    }
    public int getCcredit(){
    	return ccredit;
    }
    public void setCcredit(int ccredit){
    	this.ccredit=ccredit;
    }
}

CouDao.java

package nuc.select.Dao;

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

import nuc.select.coon.Coon;
import nuc.select.course.Course;
import nuc.select.student.Student;

public class CouDao {
	 public int Insert(Course course){
  	   int rst=0;
  	   Coon coursecoon=new Coon();
  	   Connection ccoona=coursecoon.getCoon(); 
  	   String sql_insert="insert into course(cno,cname,cteacher,ccredit) values (?,?,?,?)";
  	   try {
			PreparedStatement pst=ccoona.prepareStatement(sql_insert);
			pst.setString(1,course.getCno());
			pst.setString(2,course.getCname());
			pst.setString(3,course.getCteacher());
			pst.setInt(4,course.getCcredit());
			rst=pst.executeUpdate();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
  	   return rst;
     }
     public int Delete(Course course){
  	   int rst=0;
  	  Coon coursecoon=new Coon();
 	   Connection ccoona=coursecoon.getCoon(); 
  	   String sql_delete="delete from course where cno=?";
  	   try {
			PreparedStatement pst=ccoona.prepareStatement(sql_delete);
			pst.setString(1,course.getCno());
			rst=pst.executeUpdate();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
  	   return rst;
     }
     public ResultSet Query(){
  	   ResultSet rst=null;
  	 Coon coursecoon=new Coon();
	   Connection ccoona=coursecoon.getCoon(); 
  	   String sql_query="select * from course";
  	   try {
			PreparedStatement pst=ccoona.prepareStatement(sql_query);
			rst=pst.executeQuery();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
  	   return rst;
     }
     public int Updates(Course course){
  	   int rst=0;
  	 Coon coursecoon=new Coon();
	   Connection ccoona=coursecoon.getCoon(); 
  	   String sql_update="update course set cname=?,cteacher=?,ccredit=? where cno=?";
  	   try {
			PreparedStatement pst=ccoona.prepareStatement(sql_update);
			pst.setString(1,course.getCname());
			pst.setString(2,course.getCteacher());
			pst.setInt(3,course.getCcredit());
			pst.setString(4,course.getCno());
			rst=pst.executeUpdate();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
  	   return rst;
     }
     public ResultSet Select(Course course){
    	   ResultSet rst=null;
    	 Coon coursecoon=new Coon();
  	   Connection ccoona=coursecoon.getCoon(); 
    	   String sql_query="select * from course where cno=?";
    	   try {
  			PreparedStatement pst=ccoona.prepareStatement(sql_query);
  			pst.setString(1,course.getCno());
  			rst=pst.executeQuery();
  		} catch (SQLException e) {
  			// TODO Auto-generated catch block
  			e.printStackTrace();
  		}
    	   return rst;
       }
}

Coon.java

package nuc.select.coon;

import java.sql.*;

public class Coon {
     public static final String DBDRIVER="org.gjt.mm.mysql.Driver";
     public static final String DBURL="jdbc:mysql://localhost:3306/select";
     public static final String DBUSER="root";
     public static final String DBPASS="*****";
     Connection coon=null;
      public  Connection getCoon(){
    	  try{
    		  Class.forName(DBDRIVER);
    		  coon=DriverManager.getConnection(DBURL,DBUSER,DBPASS);
    	  }catch(Exception e){
    		e.printStackTrace();
    	  }
    	  return coon;
      }
    
}
insertCourse.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<form action="doinsertCourse.jsp" method="post">
课程号<input type="text" name="cno">  
课程名<input type="text" name="cname">  
老师<input type="text" name="cteacher">  
学分<input type="text" name="ccredit">  
<input type="submit" value="添加">
<input type="reset" value="重置">
 </form>
</body>
</html>
deleteCourse.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    <%@ page import="java.sql.*" %>
    <%@ page import="nuc.select.Dao.*" %>
    <%@ page import="nuc.select.course.*" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<%
	CouDao cou=new CouDao();
	Course coun=new Course();
	coun.setCno(request.getParameter("cno"));
	int rs=cou.Delete(coun);
	if(rs>0){
	   	out.println("删除成功!");
	}
	else{
	   	out.println("删除失败!");
	}
%>
</body>
</html>
updateCourse.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
     <%@ page import="java.sql.*" %>
    <%@ page import="nuc.select.Dao.*" %>
    <%@ page import="nuc.select.course.*" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<%
   request.setCharacterEncoding("utf-8");	
   CouDao cou=new CouDao();
   Course coun=new Course();
   coun.setCno(request.getParameter("cno"));
   ResultSet rs=cou.Select(coun);
	if(rs.next()){
%>
<form action="doupdateCourse.jsp?cno=<%=rs.getString("cno") %>" method="post">
课程号<input type="text" name="cno" value="<%=rs.getString("cno") %>">  
课程名<input type="text" name="cname" value="<%=rs.getString("cname") %>">  
老师<input type="text" name="cteacher" value="<%=rs.getString("cteacher") %>">  
学分<input type="text" name="ccredit" value="<%=rs.getString("ccredit") %>">  
<input type="submit" value="修改">
<input type="reset" value="取消">
 </form>
<%} %>
</body>
</html>
doupdateCourse.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    <%@ page import="java.sql.*" %>
    <%@ page import="nuc.select.course.*" %>
    <%@ page import="nuc.select.Dao.*" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<% request.setCharacterEncoding("utf-8"); %>
<jsp:useBean id="cour" class="nuc.select.course.Course">
<jsp:setProperty name="cour" property="*" />
</jsp:useBean>
<%
CouDao cou=new CouDao();
Course coun=new Course();
coun.setCno(request.getParameter("cno"));
int rs=cou.Updates(cour);
if(rs>0){
	out.println("修改成功!");
}else{
	out.println("修改失败!");
}
%>
</body>
</html>
queryCourse.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
     <%@ page import="java.sql.*" %>
    <%@ page import="nuc.select.course.*" %>
    <%@ page import="nuc.select.Dao.*" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>课程信息显示</title>
<style type="text/css">
td{
  text-align:center;
}
a{
  text-decoration:none;
}
</style>
</head>
<body>
<center>
<%
	CouDao cou=new CouDao();
	Course coun=new Course();
	ResultSet rs=cou.Query();
%>
<table border="1" width="500" height="500">
<caption>课程信息</caption>
<tr><td>课程号</td><td>课程名</td><td>老师</td><td>学分</td><td colspan="2">数据操作</td></tr>
<% 
	while(rs.next()){
%>
<tr>
<td><%=rs.getString("cno") %></td>
<td><%=rs.getString("cname") %></td>
<td><%=rs.getString("cteacher") %></td>
<td><%=rs.getString("ccredit") %></td>
<td><a href="deleteCourse.jsp?cno=<%=rs.getString("cno") %>">删除</a></td>
<td><a href="updateCourse.jsp?cno=<%=rs.getString("cno") %>">修改</a></td>
</tr>	
<%
	} 
%>
</table>
<a href="insertCourse.jsp" style="text-decoration:none;">添加</a>
</center>
</body>
</html>





评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

涛涛之海

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值