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>

  • 相关阅读:
    MAC LAMP环境 php执行使用问题
    centos 服务器 安全设置
    Linux系统发现占用CPU达100%的进程并处理
    git 使用国内镜像 ,查看镜像更改情况
    mac安装composer
    MySql反向模糊查询
    Linux启动或重启网卡
    MAMP环境 nginx配置忽略index.php入口文件
    php 验证码生成 不保存的情况下 缩小图片质量
    KMP字符串模式匹配详解
  • 原文地址:https://www.cnblogs.com/atwanli/p/mm.html
Copyright © 2011-2022 走看看