Java -- access SQL Server 2000 through eclipse

Source: Internet
Author: User

I have asked the experts in the group. After I have explained my questions over and over again, I still cannot access SQL Server 2000 in my java code.

Fortunately, the world's communication is very developed. During my nearly two days of Baidu (I just started to learn Java), my problem was finally solved by myself.

First, I tried to use jtds. jar as the driver to access SQL Server 2000.

In this way, note that the port of SQL Server 2000 must be enabled. The default value is 1433.

How to view the port: Microsoft SQL Server --> server network utility --> select TCP/IP --> Properties

Test method: first start SQL Server:

1: Telnet the hostname port to check whether it can be connected.

2: Run netstat-A or netstat-An to check whether port 1433 is active.

If the test shows that the connection fails or port 1433 is not an active port, your SQL Server 2000 must be patched with SP3 or SP4.

Chinese SP4 patch address if your SQL Server 2000 is in English, please switch to English in the language bar. After the patch is downloaded and installed, remember

Run start. bat... to test it.

After the SQL server problem is solved, download the jtds. jar package and import it to jtds. jar.

Test code:

..........

Import net. SourceForge. jtds. JDBC. driver;

.......
Class. forname ("net. SourceForge. jtds. JDBC. Driver ");
Connection conn = drivermanager. getconnection "JDBC: jtds: sqlserver: // 127.0.0.1: 1433; databasename = xx", "sa", "dba ");

 

 

Since downloading SP4 is slow, I try to connect through a bridge:

Jdk1.4 and later versions, with the idbc-ODBC driver.

Next, configure the ODBC Data Source. Administrative Tools --> ODBC Data Source manager --> User DSN --> Add --> select SQL Server. Next, follow the instructions below:

Indicates that the configuration is complete. Remember the data source name.

Test code:

.....

Import sun. JDBC. ODBC. jdbcodbcdriver;

.......

Class. forname ("Sun. JDBC. ODBC. jdbcodbcdriver"). newinstance ();
String url = "JDBC: ODBC: name of the configured data source ";
String user = "sa ";
String Password = "dba ";
Connection conn = drivermanager. getconnection (URL, user, password );

.....

OK

Related Article

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.