Take tomcat4.1.29 as an Example
1. Copy the driver file of the database to Tomcat in the WEB-INF/lib folder under your webapp
2, start Tomcat, enter the administrator interface (Tomcat home page has a link in the upper left corner, if you do not know the password, please open the conf folder in the Tomcat file under the tomcat-users.xml file, with notepad can open, it contains the admin user name and password, and the admin default password is blank)
3. Click Tomcat server> service> host> context> resources> data sources in the left column.
4. In the data source actions drop-down box on the right, select create new data source >>> and configure the datasource information.
Take MSSQL as an example:
JNDI name: JDBC/MSSQL
Data source URL: JDBC: Microsoft: sqlserver: // 192.168.0.52: 1433; databasename = Abu
JDBC Driver Class: COM. Microsoft. JDBC. sqlserver. sqlserverdriver
User name: Abu
Password: Abu
Max. Active connections: 4
Max. Active connections: 2
Max. Wait for connection: 5000
Validation query: // you can leave it empty.
5. Click Save> Commit Changes in the header of the page.
6. Restart the service and enter the following in the test page:Code
<% @ Page import = "Java. SQL. *" %>
<% @ Page import = "javax. SQL. *" %>
<% @ Page import = "javax. Naming. *" %>
<%
Datasource DS = NULL;
Try {
Initialcontext CTX = new initialcontext ();
DS = (datasource) CTX. Lookup ("Java: COMP/ENV/jdbc/MSSQL ");
Connection conn = Ds. getconnection ();
Statement stmt = conn. createstatement ();
String strsql = "select * From TTT ";
Resultset rs = stmt.exe cutequery (strsql );
While (Rs. Next ()){
System. Out. println (Rs. getstring (1 ));
}
}
Catch (exception ex ){
Ex. printstacktrace ();
}
%>
7. You should be able to see the printed items on the console.
I hope this will help you.