• JSP之连接SQL Server


    1、在SQL Server中启用sa(请参考本人博客:http://www.cnblogs.com/zhouhb/archive/2011/02/15/1955324.html)
    2、在SQL Server配置管理器中启用TCP/IP

    3、双击TCP/IP,在弹出的窗口中选择“IP地址选项卡”,将IP1【IP地址】设为127.0.0.1

    4、在上一步的窗口中将滚动条拖到最下方,将IPAll中的【TCP端口】设置成【1433】

    5、重启SQL Server服务
    6、下载数据库厂商提供的驱动程序包sqljdbc4.jar,拷贝到web项目的WEB-INFlib目录下
    7、编程,通过纯Java驱动方式与数据库建立连接

    <%@ page language="java" contentType="text/html; charset=GB18030"
    pageEncoding="GB18030"%>
    <%@ 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=GB18030">
    <title>Insert title here</title>
    </head>
    <body>
    <%
    String URL = "jdbc:sqlserver://127.0.0.1:1433;databaseName=addresslist";
    Connection con = null;
    try {
    Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
    con = DriverManager.getConnection(URL, "sa", "123");
    out.print("连接成功<br/>");
    } catch (Exception e) {
        e.printStackTrace();
      } finally {
      try {
          con.close();
        } catch (Exception e2) {
      }
    }
    %>
    </body>
    </html>

    页面上显示“连接成功”,则表示配置正确。

  • 相关阅读:
    strcmp()比较函数和strcasecmp()和strnatcmp()
    substr()函数
    改变字符串中的字母大小写
    explode()与相反函数 implode() 和join()
    PHP nl2br() 函数
    PHP trim() 函数
    PHP的count(数组)和strlen(字符串)的内部实现
    变量处理函数库
    php中定义数组的方法
    80端口的烦恼:[3]清除NT Kernel占用80端口
  • 原文地址:https://www.cnblogs.com/zhouhb/p/6779954.html
Copyright © 2020-2023  润新知