赞
踩
A 安装SQL Server 2005
帐户类型:本地系统
身份验证模式:混合模式
usr_id:sa
pwd:list_seq
实例名:默认
B 使用JDBC 1.2连接SQL Server 2005
1 据说因为SQL SERVER2005被攻击,所以SP2版对LOCALHOST端口1433进行了屏蔽
进入Micro Sql Server 2005->配制工具->SQL Server Configuration Manager
->SQL Server配制管理 器(本地)
->SQL Server 2005 网络配制
->MSSQLSERVER的协议->TCP/IP
启用1433端口,启用tct/ip协议.
重起Microsoft SQL Server Management Studio.
2 连接数据库
2.1 web应用连通性测试
本地deploy一个Weblogic的Web应用,进入控制台http://localhost:7001/console
配置 Connection Pool:
Database Type:MS SQL Server
Database Driver: *BEA's MS SQL Server Driver (Type 4) Versions:7.0, 2000
测试成功
2.2 java应用程序连接性测试(以下为test.java文件的内容)
** 需要两个文件的支持: sqljdbc_auth.dll , 放在WEB应用的根目录下. sqljdbc.jar,放在C:/Program Files/Microsoft SQL Server 2005 JDBC Driver/sqljdbc_1.2/chs/sqljdbc.jar, 并加入WEB应用的.classpath中即可.
public class test
{
public static void main(String[] args)
{
//Create a variable for the connection string.
String connectionUrl = "jdbc:sqlserver://localhost:1433;integratedSecurity=true;databaseName=scx;";
// Declare the JDBC objects.
Connection con = null;
Statement stmt = null;
ResultSet rs = null;
try
{
// Establish the connection.
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
con = DriverManager.getConnection(connectionUrl);
// Create and execute an SQL statement that returns some data.
String SQL = "SELECT * FROM usr_info";
stmt = con.createStatement();
rs = stmt.executeQuery(SQL);
// Iterate through the data in the result set and display it.
while (rs.next())
{
System.out.println(rs.getString(1) + " " + rs.getString(2));
}
}
catch (Exception e)
{
e.printStackTrace();
}finally
{
if (rs != null)
try
{
rs.close();
} catch(Exception e)
{
System.out.println(e.toString());
}
if (stmt != null)
try
{
stmt.close();
}catch(Exception e)
{
System.out.println(e.toString());
}
if (con != null)
try
{
con.close();
}catch(Exception e)
{
System.out.println(e.toString());
}
}
}
}
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。