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>

  • 相关阅读:
    Model, View(Camera), Perspective (1)
    流状态和c++的异常处理
    VAO VBO EBO(3)
    VAO VBO EBO(2)
    VAO VBO EBO(1)
    函数指针(2)
    函数指针
    内联函数和宏函数的一些区别
    关于宏的一些知识
    关于未来方向
  • 原文地址:https://www.cnblogs.com/atwanli/p/mm.html
Copyright © 2011-2022 走看看