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>

  • 相关阅读:
    SQL里面的函数应用
    Split的小用法
    堆栈和堆问题
    break,continue,goto,Return几个方法
    接口笔记
    抽象类
    虚方法
    将博客搬至CSDN
    运行数据区
    美团-走迷宫
  • 原文地址:https://www.cnblogs.com/atwanli/p/mm.html
Copyright © 2011-2022 走看看