Jsp 访问SQLsever2008R2

来源:互联网 发布:genbank数据库记录 编辑:程序博客网 时间:2024/06/14 03:48
<%@ page language="java" contentType="text/html; charset=UTF-8"    pageEncoding="UTF-8" import="java.util.Date"%><%@ page 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=ISO-8859-1"><title>Insert title here</title></head><body>                <%         String url = "jdbc:sqlserver://202.195.145.169:1368;databaseName=Student;user=sa;password=123456";//sa身份连接             Connection con = null;             Statement stmt = null;             ResultSet rs = null;                  try {           Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");              con = DriverManager.getConnection(url);                    String SQL = "SELECT * FROM Login";                 stmt = con.createStatement();                 rs = stmt.executeQuery(SQL);                 while (rs.next()) {            %>                  <%=rs.getString("Name")%> <br/>        <%              }             }           catch (Exception e) {                 e.printStackTrace();             }                  finally {                 if (rs != null)                     try {                         rs.close();                     } catch (Exception e) {                     }                 if (stmt != null)                     try {                         stmt.close();                     } catch (Exception e) {                     }                 if (con != null)                     try {                         con.close();                     } catch (Exception e) {                     }             }                    %></body></html>

0 0
原创粉丝点击