11.20

<%@ 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();
}
}
%>

posted @   new菜鸟  阅读(8)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· .NET10 - 预览版1新功能体验(一)
点击右上角即可分享
微信分享提示