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