|
@@ -0,0 +1,53 @@
|
|
|
+<%--
|
|
|
+ Created by IntelliJ IDEA.
|
|
|
+ User: Jason
|
|
|
+ Date: 2022/4/6
|
|
|
+ Time: 10:22
|
|
|
+ To change this template use File | Settings | File Templates.
|
|
|
+--%>
|
|
|
+<%@ page language="java" import="java.sql.Connection" contentType="text/html; charset=UTF-8"
|
|
|
+ pageEncoding="GB18030" import="java.sql.*"%>
|
|
|
+<!DOCTYPE html>
|
|
|
+<html>
|
|
|
+<head>
|
|
|
+ <title>JSP 读取数据库</title>
|
|
|
+</head>
|
|
|
+<body>
|
|
|
+<table border="1" align="center">
|
|
|
+<tr>
|
|
|
+ <th>code</th>
|
|
|
+ <th>sex</th>
|
|
|
+ <th>name</th>
|
|
|
+ <th>age</th>
|
|
|
+</tr>
|
|
|
+ <%
|
|
|
+ String driverClass="com.mysql.jdbc.Driver";
|
|
|
+ String url="jdbc:mysql://localhost:3306/data";//<数据库名称>
|
|
|
+ String user="root";
|
|
|
+ String password="123456";
|
|
|
+ try{
|
|
|
+ Class.forName(driverClass);
|
|
|
+ Connection conn;
|
|
|
+ conn=DriverManager.getConnection(url, user, password);
|
|
|
+ Statement stmt=conn.createStatement();
|
|
|
+ ResultSet rs=stmt.executeQuery("select * from student");
|
|
|
+ while(rs.next()){
|
|
|
+ %>
|
|
|
+ <tr>
|
|
|
+ <td><%=rs.getString("code")%></td>
|
|
|
+ <td><%=rs.getString("sex")%></td>
|
|
|
+ <td><%=rs.getString("name")%></td>
|
|
|
+ <td><%=rs.getString("age")%></td>
|
|
|
+ </tr>
|
|
|
+ <%
|
|
|
+ }
|
|
|
+ stmt.close();
|
|
|
+ conn.close();
|
|
|
+ }catch (Exception ex){
|
|
|
+ System.out.println("找不到驱动");
|
|
|
+ ex.printStackTrace();
|
|
|
+ }
|
|
|
+ %>
|
|
|
+ </table>
|
|
|
+</body>
|
|
|
+</html>
|