zoukankan      html  css  js  c++  java
  • jsp连接Sql2008查询操作

    <%@ page language="java" contentType="text/html; charset=gb2312"
     pageEncoding="gb2312" import="java.sql.*"%>
    <!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=gb2312">
    <title>添加数据</title>
    </head>
    <body>
     <center>
      <table border=1 cellspacing="1">
       <tr>
        <th>id</th>
        <th>name</th>
        <th>age</th>
        <th>address</th>
        <th>city</th>
       </tr>
       <%
        String url = "jdbc:sqlserver://localhost:1433; DatabaseName=JavaJdbc";
        String user = "sa";
        String password = "110";
        Connection conn = null;
        PreparedStatement pstmt = null;
        String driverName = "com.microsoft.sqlserver.jdbc.SQLServerDriver";
        try {
          Class.forName(driverName).newInstance();
         conn = DriverManager.getConnection(url, user, password);
        } catch (ClassNotFoundException e) {
         out.println(e);
        } catch (SQLException e) {
         out.println("连接SQLserver数据库失败!!!!!!");
        }
        
        
        
        
        Statement stmt = conn.createStatement();
        ResultSet rs = stmt.executeQuery("select * from employee");
        while (rs != null && rs.next()) {
         out.print("<tr><td>" + rs.getInt("id") + "</td>");
         out.print("<td>" + rs.getString("name") + "</td>");
         out.print("<td>" + rs.getInt("age") + "</td>");
         out.print("<td>" + rs.getString("address") + "</td>");
         out.print("<td>" + rs.getString("city") + "</td></tr>");
        }

       %>
      </table>
     </center>
    </body>
    </html>

  • 相关阅读:
    硬件_WIFI&Blue
    C++_练习—多态_纯虚函数与抽象类
    C++_练习—多态_验证vptr分布初始化
    C++_练习—多态_证明vptr指针的存在
    单摆方程
    谐振动相关知识
    UVa 129
    LeetCode-316
    Java 运算符
    一些特殊的矩阵
  • 原文地址:https://www.cnblogs.com/atwanli/p/mm.html
Copyright © 2011-2022 走看看