jsp页面直接读取mysql数据库数据显示:

<%@page import="java.sql.ResultSet"%>
<%@page import="com.mysql.jdbc.Statement"%>
<%@page import="java.sql.DriverManager"%>
<%@page import="com.mysql.jdbc.Connection"%>
<%@ page language="java" contentType="text/html; charset=gbk"
    pageEncoding="gbk"%>
<!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=gbk">
<title>Insert title here</title>
</head>
<body>
    <%
        //加载驱动
        Class.forName("com.mysql.jdbc.Driver");
        //建立连接
        Connection conn = (Connection) DriverManager.getConnection("jdbc:mysql://localhost:3306/house", "root",
                "123456");
        //创建Statement
        Statement stm = (Statement) conn.createStatement();
        //执行查询
        ResultSet rs = stm.executeQuery("select username,pwd from user");
    %>
    <table border="1" width="300">
        <%
            //遍历结果
            while (rs.next()) {
        %>
        <tr>
            <td><%=rs.getString(1)%></td>
            <td><%=rs.getString(2)%></td>
        </tr>
        <%
            }
        %>
    </table>
</body>
</html>

 

相关文章:

  • 2021-07-19
  • 2021-04-24
  • 2021-10-15
  • 2022-12-23
  • 2021-09-21
  • 2021-12-10
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-29
  • 2021-08-04
  • 2022-12-23
  • 2021-11-20
相关资源
相似解决方案