JDBC-ODBC bridge to access the SQL Server2000 Database, and JDBC driver implementation has many similarities, the difference is that the need to configure the data source, but does not need JDBC driver.
Create an SQL Server 2000 database
Start SQL Server 2000 Database Service Manager:
Open the Enterprise Manager, create a database, sky2098, and create a table, student, in the database ,:
Configure the data source
Select the data source configuration options as shown in:
Note that my system is Windows Server 2003. You only need to find this option to configure the data source. Then, the following window is displayed:
Select the system DSN tab. Otherwise, the connection may fail. Click Add:
Select "SQL Server" near the last position in the list box, and click "finish:
Enter the name of the data source you want to configure in the "name" location, and select local in the "server" location. You can select it based on the actual situation, and then click the "Next" button:
Here, you can set logon authentication. There are two options. Here, I select the SQL Server Logon account and click the "Next" button:
If the logon name and password of the SQL Server account are incorrect in the previous step, a message indicating a failure is displayed. For convenience, you can use the first Windows NT authentication.
Because I have created the table student in the database sky2098, I chose the database sky2098 as the default database and click the "Next" button:
In this step, follow the default configuration and click "finish:
The configuration information of the data source is displayed. Next, test the configured data source and click "Test Data Source:
The successful data source test information is displayed. Click OK to complete the data source configuration process.
Implement database access programs and other configurations
The directory hierarchy is as follows:
Relatively simple.
Below is the JSP file we tested to access the database, my named jdbc-odbc-student.jsp, the Code is as follows:
<%... @ Page contenttype = "text/html; charset = gb2312" Language = "Java" Import = "Java. SQL. *, java. Io. *" %>
<HTML>
<Body>
<Center>
<H1> student admission Information <HR>
<Table border = 1>
<Tr> <TD> Student ID </TD> <TD> name </TD> <TD> age </TD> <TD> from </TD> <TD> school </TD> <TD> major </TD> <TD> score </TD> </tr>
<%...
Class. forname ("Sun. JDBC. ODBC. jdbcodbcdriver ");
Connection con = drivermanager. getconnection ("JDBC: ODBC: sqlstudent", "sa", "sky2098"); // sqlstudent is the name of the data source we configured.
Statement stmt = con. createstatement ();
Resultset rs1_stmt.exe cutequery ("select * from student ");
While (Rs. Next ())
{
Out. println ("<tr> ");
Out. println ("<TD>" + Rs. getint ("num") + "</TD> ");
Out. println ("<TD>" + Rs. getstring ("name") + "</TD> ");
Out. println ("<TD>" + Rs. getint ("Age") + "</TD> ");
Out. println ("<TD>" + Rs. getstring ("fromw") + "</TD> ");
Out. println ("<TD>" + Rs. getstring ("school") + "</TD> ");
Out. println ("<TD>" + Rs. getstring ("Major") + "</TD> ");
Out. println ("<TD>" + Rs. getint ("score") + "</TD> ");
Out. println ("</tr> ");
Out. println ("</tr> ");
}
Rs. Close ();
Stmt. Close ();
Con. Close ();
%>
</Table>
</Body>
</Html>
Start Tomcat web server
To do the above work, you can start the Web Server ,:
Open IE and enter the hyperlink address:
Http: // localhost: 8080/sqlserver/jdbc-odbc-student.jsp
To access the SQL Server 2000 database ,:
So far, the realization of JDBC-ODBC Bridge access SQL Server2000 Database function.