How to Use JDBC to connect to Ms sqlserver 2000 in Windows XP SP2

Source: Internet
Author: User

1.1433 port problems
In SP2, the firewall disables this port by default. Open it by yourself. Control Panel-firewall-exception, add TCP 1433 port UDP 1433

2. Download SQL Server 2000 driver for JDBC
SQL Server 2000 driver for JDBC downloads
The driver has four versions so far. We recommend that you download the latest SP3 version.
After the driver is successfully installed, install the three drivers in the lib directory. jar files are added to classpath. If you are using JBuilder or eclipse, add these three files to the project according to the IDE prompts.

3. Upgrade Your SQL Server 2000 and install the latest patches.
Install the latest SQL Server 2000 Patch (SP4) and JDBC Driver (SP3 ).
If your program prompts "Error establishing socket" during running, you can fix it by patching SQL Server 2000.

4. Driver Loading Method
Before establishing a connection, load the SQL Server 2000 JDBC driver. The code format is as follows:
Class. forname ("com. Microsoft. JDBC. sqlserver. sqlserverdriver ");

5. Get a connection
Before operating the database, you must first obtain a connection to the database, using the following code format:
Drivermanager. getconnection (connection string, logon user name, logon password );
Example:
Drivermanager. getconnection ("JDBC: Microsoft: sqlserver: // localhost: 1433; databasename = pubs", "sa ","");
The key here is the content of the connection string. the localhost part is the name of the server, which can be changed; the localhost part is the port number used by SQL Server, which can be modified according to the actual situation; databasename is the name of the database to be connected. Note that the database name before databasename is a semicolon rather than a colon.

6. code example

// Import the Java SQL package. It is required to connect to the database;
Import java. SQL .*;

Public class testdb {
Public static void main (string [] ARGs ){
String drivername = "com. Microsoft. JDBC. sqlserver. sqlserverdriver ";
String dburl = "JDBC: Microsoft: sqlserver: // localhost: 1433; databasename = pubs ";
String username = "sa ";
String userpwd = "";
Connection dbconn

Try {
Class. forname (drivername );
Dbconn = drivermanager. getconnection (dburl, username, userpwd );
System. Out. println ("connection successful! ");
}
Catch (exception e ){
E. printstacktrace ();
}
}
}

6. Possible Problems
If the above Code is run, output "connection successful! ", It means that everything is normal, and the database is connected successfully. You can perform statement and resultset operations. Otherwise, exceptions may occur.
If the error "Error establishing socket" is prompted, install the corresponding SQL Server 2000 patch according to the previous instructions.
If "classnotfoundexception" is prompted, it must be a class. forname ("com. microsoft. JDBC. sqlserver. sqlserverdriver "); the Code in this section is misspelled, or it is three in the SQL Server 2000 driver for JDBC lib directory. the jar file is not added to classpath.

 

How to view the sqlserver version

Run the SQL Server service manager. Right-click the manager icon in the tray of the taskbar and select "About". In the displayed window, check the following information.
8.00.194 ------- SQL Server 2000 RTM
8.00.384 ------- SQL Server 2000 (SP1)
8.00.534 ------- SQL Server 2000 (SP2)
8.00.760 ------- SQL Server 2000 (SP3)
8.00.2039 ------- SQL Server 2000 (SP4)

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.