2015-06-08|3328阅|作者:Essence|举报 摘要:<%@ page language="java" contentType="text/html; charset=gb2312"
pageEncoding="gb2312"%>
<%@ page import="java.sql.*" %>
<%@ page language="java" contentType="text/html; charset=gb2312"
pageEncoding="gb2312"%>
<%@ page import="java.sql.*" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>学生管理</title>
</head>
<body>
<%
Class.forName("com.mysql.jdbc.Driver");
String url="jdbc:mysql://127.0.0.1/JJUDB?"
+"&useUnicode=true&characterEncoding=GB2312";
String user="root";
String pass="110806";
Connection conn=DriverManager.getConnection(url,user,pass);
Statement stmt = conn.createStatement();
String sql= "select * from Student";
ResultSet rs = stmt.executeQuery(sql);
%>
<table border="1">
<tr>
<th>id</th>
<th>学号</th>
<th>姓名</th>
<th>班级</th>
</tr>
<% while(rs.next()){ %>
<tr>
<td><%=rs.getInt("id") %></td>
<td><%=rs.getString("studentNo") %></td>
<td><%=rs.getString("studentName") %></td>
<td><%=rs.getInt("gradeId") %></td>
</tr>
<% }
rs.close();
stmt.close();
conn.close(); %>
</table>
<a href="studentAdd.jsp">添加学生信息</a>
</body>
</html>
<%@ page language="java" contentType="text/html; charset=gb2312"
pageEncoding="gb2312"%>
<%@ page import="java.sql.*" %>
<html>
<head>
<title>学生管理</title>
</head>
<body>
<%
Class.forName("com.mysql.jdbc.Driver");
String url="jdbc:mysql://127.0.0.1/JJUDB?"
+"&useUnicode=true&characterEncoding=GB2312";
String user="root";
String pass="110806";
Connection conn=DriverManager.getConnection(url,user,pass);
Statement stmt = conn.createStatement();
String sql= "select * from Grade order by id";
ResultSet rs = stmt.executeQuery(sql);
%>
<form action="studentAddAction.jsp" method="post">
<label>学号</label> <input type="text" name="studentNo"> <br>
<label>姓名</label><input type="text" name="studentName"> <br>
<label>班级</label> <select name="gradeId">
<%
while (rs.next()){
%>
<option value=<%=rs.getInt("id") %>>
<%=rs.getString("gradeName") %></option>
<%
}
rs.close();
stmt.close();
conn.close();
%>
</select><br><input type="submit" value="增加">
</body>
</html>