zoukankan      html  css  js  c++  java
  • jsp页面直接读取mysql数据库数据显示

    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>
  • 相关阅读:
    Luogu P3371 线段树1
    8-16模拟赛
    Luogu P1313 计算系数
    Luogu P1525 关押罪犯
    Luogu P1040 加分二叉树
    Luogu P1018 乘积最大
    Luogu P1541 乌龟棋
    BST,Splay平衡树学习笔记
    常见的逻辑错误
    行为认知疗法——十大认知错误
  • 原文地址:https://www.cnblogs.com/ming-4/p/11908464.html
Copyright © 2011-2022 走看看