簡單學生選課系統之學分彙總
阿新 • • 發佈:2019-01-10
ScDao.java
public ResultSet selectcredit(){ ResultSet rst=null; Coon coona=new Coon(); Connection coonn=coona.getCoon(); String sql="select scno,sno,sname from sc group by sno having sum(ccredit)<15"; try { PreparedStatement pst=coonn.prepareStatement(sql); rst=pst.executeQuery(); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } return rst; }
queryStudent.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@ page import="java.sql.*" %> <%@ 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; } </style> </head> <body> <center> <% request.setCharacterEncoding("utf-8"); ScDao sc=new ScDao(); ResultSet rs=sc.selectcredit(); if(rs!=null){ %> <table border="1" width="500" height="500"> <caption>學分不夠的情況</caption> <tr><td>班級</td><td>學號</td><td>姓名</td></tr> <% while(rs.next()){ %> <tr> <td><%=rs.getString("scno") %></td> <td><%=rs.getString("sno") %></td> <td><%=rs.getString("sname") %></td> </tr> <% } }else{ out.println("沒有學分不夠的學生!"); } %> </table> </center> </body> </html>