[
原创
]
JDBC
如何连接
SQL SERVER 2000
的默认实例和命名实例
引用请注明出处
:http//www.blogjava.net/SINOJAVA
(
一
)
下载
Microsoft SQL Server 2000 Service Pack 3a
并安装
http://www.microsoft.com/downloads/details.aspx?FamilyId=90DCD52C-0488-4E46-AFBF-ACACE5369FA3&displaylang=zh-cn
(
二
)
下载并安装
SQL SERVER 2000
得
JDBC
驱动
(
SQL Server 2000 Driver for JDBC Service Pack 3
)
http://www.microsoft.com/downloads/details.aspx?FamilyId=07287B11-0502-461A-B138-2AA54BFDC03A&displaylang=en
(
三
)
配置
JDBC
驱动
classpath
环境变量
:
方法
1:
填加
:
C:\Program Files\Microsoft SQL Server 2000 Driver for JDBC\lib\msbase.jar;
C:\Program Files\Microsoft SQL Server 2000 Driver for JDBC\lib\mssqlserver.jar;
C:\Program Files\Microsoft SQL Server 2000 Driver for JDBC\lib\msutil.jar;
注
: C:\Program Files\Microsoft SQL Server 2000 Driver for JDBC\
为我
JDBC
得安装路径
方法
2:
将
mssqlserver.jar; msutil.jar; msbase.jar
拷贝到
JDK
得
lib
目录下
,
然后设置
classpath
D:\Java\jdk1.5.0_05\lib\sqlserver\msutil.jar;
D:\Java\jdk1.5.0_05\lib\sqlserver\msbase.jar;
D:\Java\jdk1.5.0_05\lib\sqlserver\mssqlserver.jar;
(
四
)
创建连接数据库默认实例得连接代码
:
import java.sql.*;
public class ConSqlserver {
Connection con=null;
//Statement st=null;
//ResultSet re=null;
public ConSqlserver()
{
try
{
String driver="com.microsoft.jdbc.sqlserver.SqlServerDriver";
String url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=Northwind";
Class.forName(driver).newInstance();
con =DriverManager.getConnection(url,"sa","zhaopf");
System.out.println("
连接成功
!");
con.close();
}
catch(Exception e)
{
e.printStackTrace();
}
}
public static void main(String[] args)
{
// TODO
自动生成方法存根
ConSqlserver con=new ConSqlserver();
}
}
(
四
)
创建连接数据库默认实例得连接代码
(
实例名为
SINOIT\SINOSERVER)
L
import java.sql.*;
public class ConSqlserverppp {
Connection con=null;
//Statement st=null;
//ResultSet re=null;
public ConSqlserverppp()
{
try
{
//String driver="com.microsoft.jdbc.sqlserver.SqlServerDriver";
String url="jdbc:microsoft:sqlserver://SINOIT\\SINOSERVER;DatabaseName=Northwind";
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();
//Class.forName(driver);//.newInstance();
con =DriverManager.getConnection(url,"sa","zse");
//st=con.createStatement();
System.out.println("
连接成功
!");
con.close();
}
catch(Exception e)
{
e.printStackTrace();
}
}
public static void main(String[] args)
{
ConSqlserverppp con=new ConSqlserverppp();
}
}
posted on 2006-04-10 07:16
SINOJAVA 阅读(3533)
评论(0) 编辑 收藏 所属分类:
Java VS DataBase