The premise is to put the required msutil. Jar MSSQLServer. Jar msbase. Jar mssqlserver4v65. Jar under tomcat/common/lib.
1,Copy the JDBC driver of the database to % atat_home %/common/lib and webcontent/Web-INF/lib of the eclipse project.
2,The node of the server. XML web program on the eclipse Server:
<Context docbase = "filemanager" Path = "/filemanager" reloadable = "true" Source = "org. Eclipse. JST. J2EE. SERVER: filemanager">
</Context>
Add the following content:
<Resource Name = "JDBC/filedb" auth = "Container"
Type = "javax. SQL. datasource" maxactive = "100" maxidle = "30"
Maxwait = "10000" username = "sa" Password = "123"
Driverclassname = "com. Microsoft. JDBC. sqlserver. sqlserverdriver"
Url = "JDBC: Microsoft: sqlserver: // localhost: 1433; databasename = filedb"/>
3,Create an XML file with the same name as your web folder under % atat_home %/CONF/Catalina/localhost (my file is filemanager. XML)
This step is very important. If this step does not exist, an error will occur, and org. apache. tomcat. DBCP. DBCP. sqlnestedexception: cannot create JDBC driver of class ''for connect URL 'null'. Add the following content to the file:
<? XML version = "1.0" encoding = "UTF-8"?>
<Context>
<Resource Name = "JDBC/filedb" auth = "Container"
Type = "javax. SQL. datasource" maxactive = "100" maxidle = "30"
Maxwait = "10000" username = "sa" Password = "123"
Driverclassname = "com. Microsoft. JDBC. sqlserver. sqlserverdriver"
Url = "JDBC: Microsoft: sqlserver: // localhost: 1433; databasename = filedb"/>
</Context>
4,Modify the Web. xml under webcontent/Web-INF of the eclipse project and add the following content before </Web-app>:
<Resource-ref>
<Description> dB connection </description>
<Res-ref-Name> JDBC/filedb </RES-ref-Name>
<Res-type> javax. SQL. datasource </RES-type>
<Res-auth> container </RES-auth>
</Resource-ref>
5,Create a new dbtest. jsp file under webcontent.
<% @ Page contenttype = "text/html; charset = GBK" %>
<% @ Page import = "Java. SQL. *" %>
<% @ Page import = "javax. SQL. *" %>
<% @ Page import = "javax. Naming. *" %>
<%
Try {
Context initcontext = new initialcontext ();
Context envcontext =
(Context) initcontext. Lookup ("Java:/COMP/ENV ");
Datasource DS =
(Datasource) envcontext. Lookup ("JDBC/filedb ");
Connection conn = Ds. getconnection ();
If (! Conn. isclosed ())
Out. println ("database connection test succeeded ");
Conn. Close ();
}
Catch (sqlexception e ){
Out. println (E. tostring ());
}
%>
Restart the server and run dbtest. jsp. Then, restart _^.
Note: mssqlserver4v65 is not imported. JAR file, causing the program to appear Org. apache. tomcat. DBCP. DBCP. sqlnestedexception: cannot create JDBC driver of class ''for connect URL 'null' error.