java连接SQL Server 2000 数据库

步骤:
1.下载JDBC Driver.
进入http://www.microsoft.com/downloads/en/results.aspx?displaylang=en&freeText=sql+server+2000+driver+for+jdbc
选择SQL Server 2000 Driver for JDBC SP3 .下载 setup.exe(2.3MB)

2.安装下载的setup.exe,安装后可以到C:\Program Files目录下找到Microsoft SQL Server 2000 Driver for JDBC文件夹,这就是刚刚安装的JDBC Driver.

3.将Microsoft SQL Server 2000 Driver for JDBC文件夹lib目录下的3个jar包的路径加到系统环境变量(CLASSPATH)中,如:
C:\program files\Microsoft SQL Server 2000 Driver for JDBC\lib\msbase.jar;
C:\program files\Microsoft SQL Server 2000 Driver for JDBC\lib\msutil.jar;
C:\program files\Microsoft SQL Server 2000 Driver for JDBC\lib\mssqlserver.jar

4.将Microsoft SQL Server 2000 Driver for JDBC文件夹lib目录下的3个jar包分别copy到%HOME_TOMCAT%\common\lib和工程的WEB-INF\lib下.

5.鼠标右击工程项目,选择properties-->Java Build Path-->Libraries,点击Add External Jars,把3个jar包导入进来.

6.配置完成,现在可以试试在java连接.
final String url = "jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=myDatabase"; // myDatabase是我建的数据库
final String userName = "sa";
final String password = "1234";
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
Connection con = DriverManager.getConnection(url, userName, password);
if(con!=null) System.out.println("Connection Successful!");
(注意:密码有可能是"",用户名和密码必须能在查询分析器的SQL Server 身份验证登录)

你可能感兴趣的:(java,sql,SQL Server,jdbc,Microsoft)