Article ID: 313100 - View products that this article applies to.
This article describes how to connect to SQL Server 2000 by using the Microsoft SQL Server 2000 driver for JDBC.
NOTE: For installation instructions for Microsoft SQL Server 2000 Driver for JDBC, see the Microsoft SQL Server 2000 Driver for JDBC Installation Guide.
After you install the Microsoft SQL Server 2000 driver for JDBC, you can connect from your program to your database in two ways: with a connection URL, or with a JNDI data source. This article describes how to configure and test your database connection by using a connection URL.
One way of connecting to a database is by through JDBC Driver Manager by using the getConnection method of the DriverManager class. The simplest manner of using this method takes a string parameter that contains an URL, a user name, and a password. The following sections in this article describe how to load the Microsoft SQL Server 2000 driver for JDBC from your JDBC program.
Set your system CLASSPATH variable to include the following entries:
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
com.microsoft.jdbc.sqlserver.SQLServerDriverThe following sample code demonstrates how to register the driver:
jdbc:microsoft:sqlserver://servername:1433The following sample code demonstrates how to specify a connection URL:
The server name values can be an IP address or a host name (assuming that your network resolves host names to IP addresses). You can test this by pinging the host name and verifying that you receive a reply with the correct IP address.
The numeric value after the server name is the port number on which the database is listening. The values that are listed earlier in this article are sample default values. Make sure to substitute the port number that your database is using.
For a complete list of connection URL parameters, see the Microsoft SQL Server 2000 Driver for JDBC HTML Help, or see the Online Guide. See the "Connection String Properties" section.
If this code is successful, the output is similar to the following:
Connection Successful! Driver Information Driver Name: SQLServer Driver Version: 2.2.0022 Database Information Database Name: Microsoft SQL Server Database Version: Microsoft SQL Server 2000 - 8.00.384 (Intel X86) May 23 2001 00:02:52 Copyright (c) 1988-2000 Microsoft Corporation Desktop Engine on Windows NT 5.1 (Build 2600: ) Avalilable Catalogs catalog: master catalog: msdb catalog: pubs catalog: tempdb
java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC][SQLServer]Login failed for user 'user'. Reason: Not associated with a trusted SQL Server connection.
This error message occurs if the SQL Server 2000 authentication mode is set to Windows Authentication mode. The Microsoft SQL Server 2000 driver for JDBC does not support connecting by using Windows NT authentication. You must set the authentication mode of your SQL Server to Mixed mode, which permits both Windows Authentication and SQL Server Authentication.
java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC]This version of the JDBC driver only supports Microsoft SQL Server 2000. You can either upgrade to SQL Server 2000 or possibly locate another version of the driver.
This error message occurs you try to connect to a SQL Server version earlier than SQL Server 2000. The Microsoft SQL Server 2000 driver for JDBC supports connectivity only with SQL Server 2000.
Article ID: 313100 - Last Review: June 22, 2014 - Revision: 4.0
Contact us for more help