dưddw

mail@pastecode.io avatar
unknown
plain_text
a year ago
2.7 kB
1
Indexable
Never
<%-- 
    Document   : index
    Created on : Jun 2, 2023, 8:48:01 PM
    Author     : MSI GTX
--%>

<%@page import="java.sql.ResultSet"%>
<%@page import="java.sql.Statement"%>
<%@page import="java.sql.Connection"%>
<%@page import="java.sql.DriverManager"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
        <script src="https://code.jquery.com/jquery-3.5.1.js"></script>
        <script src="https://cdn.datatables.net/1.13.4/js/jquery.dataTables.min.js"></script>
        <script>
            $(document).ready(function () {
                $('#example').DataTable();
            });
        </script>
        <link rel="stylesheet" href="https://cdn.datatables.net/1.13.4/css/jquery.dataTables.min.css"/>
    </head>
    <body>
        <h1>Demo!</h1>
        
        
        <table id="example">
            <thead>
                <tr>
                    <td>id</td>
                    <td>name</td> 
                    <td>image</td>
                    <td>price</td>
                    <td>title</td>
                    <td>description</td>
                    <td>cateID</td>
                    <td>sell_ID</td>
                </tr>
            </thead>
            <%
                //khai baso driver
                Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");

                Connection conn = DriverManager.getConnection("jdbc:sqlserver://PHUCPHAN:1433;databaseName=Wish;user=sa; password=Phuc300803@;encrypt=true;trustServerCertificate=true;");  //1433 cong mat dinh
                // tao doi tuong truy van du lieu
                Statement st = conn.createStatement();
                // tao cau lenh truy van
                String sql = "select * from product";
                //thuc thi cau lenh truy van du lieu va luu ket qua
                ResultSet rs = st.executeQuery(sql);
                while (rs.next()) {
            %>

            <tr>
                <td><%= rs.getInt("id")%></td>
                <td><%=  rs.getString("name")%></td>
                <td><%= rs.getString("image")%></td>
                <td><%= rs.getString("price")%></td>
                <td><%= rs.getString("title")%></td>
                <td><%= rs.getString("description")%></td>
                <td><%= rs.getInt("cateID")%></td>
                <td><%= rs.getInt("sell_ID")%></td>

            </tr>





            <%
                }
            %>
        </table>
    </body>
</html>