1. Download SQL Server2000's JDBC driver has this driver in Microsoft Site: Window operating system http://download/sqlsvr2000/jdbc/2000/nt45xp/en-us/setup.exe There are Pack1 and PACK2, and it is also down. 2, install the JDBC and two packs to execute the MS_JDBC_SETUP.EXE executable, everything just click Next, until the Finish button appears, complete the installation. MS_JDBC_SETUP default installation path is C: / Program Files / Microsoft SQL Server 2000 Driver for JDBC; this version (Version 2.2.0022) only supports Microsoft SQL Server 2000 Driver for JDBC; the three JAR files under installation directory / lib / under the installation directory / LIB / We want JDBC driver core, these three files are: msbase.jar, mssqlser.jar, msutil.jar3, add the above three JAR files to the environment variable to ClassPath: C: / Tomcat 5.0 / Common / lib / Msbase.jar C: / Tomcat 5.0 / Common / lib / mssqlserver.jar C: / Tomcat 5.0 / Common / lib / msutil.jar 4, test import java.sql. *; public class test {public static void main (String Args) []) {Try {class.Forname ("com.microsoft.jdbc.sqlser.sqlserdriver); connection conn = drivermanager.getConnection (" JDBC: Microsoft: SQLServer: // localhost: 1433; user = **; password = ****; databasename = northwind "); statement stmt = conn.createstatement (); string sql =" select * from Employees "; ResultSet RS = Stmt.executeQuery (SQL); while (rs.next ()) {system .out.println ("testname:" rs.getstring ("firstname"));}} rs.close (); stmt.close (); conn.close ();} C ATCH (Exception EX) {System.err.Println (ex.getMessage ());}}
}
Compile, run: Javac Test.javajava Test results are:
C: /> java testsqltestname: AndrewTestName: margarettestname: machinetestname: roberttestname: roberttestname: Lauratestname: Lauratestname: Lauratestname: anne