<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page import="java.sql.*" %>
<%@ page import="javax.naming.*" %>
<%@ page import="javax.*" %>
<html>
<body>
<!-- 浏览课程信息 -->
<h3>浏览课程信息</h3>
<%
Connection conn = null;
Statement stmt = null;
ResultSet rs = null;
try {
Class.forName("com.mysql.cj.jdbc.Driver");
String url = "jdbc:mysql://localhost:3306/demo?useSSL=false";
String username = "root";
String password = "123456";
conn = DriverManager.getConnection(url, username, password);
stmt = conn.createStatement();
String query = "SELECT * FROM class1";
rs = stmt.executeQuery(query);
%>
<table>
<tr>
<th>课程ID</th>
<th>课程名称</th>
<th>班级数量</th>
<th>教师</th>
</tr>
<% while (rs.next()) { %>
<tr>
<td><%= rs.getString("id") %></td>
<td><%= rs.getString("name") %></td>
<td><%= rs.getString("number") %></td>
<td><%= rs.getString("name1") %></td>
</tr>
<% } %>
</table>
<%
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if (rs != null) rs.close();
if (stmt != null) stmt.close();
if (conn != null) conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
%>