Summary of open source technology Tomcat data source configuration

Source: Internet
Author: User
Tags mssql server

The tomcat5.0.28 + mssqlserver2000 + ms jdbc driver is successfully configured.

1. install Tomcat 5.0.28

Ii. Install Ms JDBC driver
Assume that the installation path is F:/green/Microsoft SQL Server 2000 JDBC, there are three files under F:/green/Microsoft SQL Server 2000 JDBC/lib: msbase. jar, sqlserver. jar, msutil. jar, and copy the three files to the % tommcat_home %/common/lib directory.

3. register the JNDI Data Source
Modify the configuration file of your application in the % tomcat_home %/CONF/Catalina/localhost/directory.
For example, one of my webdemo. xml files is as follows:
<? XML version = '1. 0' encoding = 'utf-8'?>
<Context workdir = "work/Catalina/localhost/webdemo" Path = "/webdemo" docbase = "D:/jakarta-tomcat-5.0.28/webapps/webdemo">
<Resource type = "javax. SQL. datasource" auth = "Container" name = "JDBC/northwind"/> bitscn. COM Network Management Alliance
<Resourceparams name = "JDBC/northwind">
<Parameter>
<Name> maxwait </Name>
<Value> 5000 </value>
</Parameter>
<Parameter>
<Name> maxactive </Name>
<Value> 4 </value>
</Parameter>
<Parameter>
<Name> password </Name>
<Value> jckjdkmcj </value>
</Parameter>
<Parameter>
Download the <Name> URL </Name> dl.bitscn.com network management software
<Value> JDBC: Microsoft: sqlserver: // 10.0.0.168: 1433; databasename = northwind </value>
</Parameter>
<Parameter>
<Name> driverclassname </Name>
<Value> com. Microsoft. JDBC. sqlserver. sqlserverdriver </value>
</Parameter>
<Parameter>
<Name> maxidle </Name>
<Value> 2 </value>
</Parameter>
<Parameter>
<Name> username </Name>
<Value> SA </value>

Bbs.bitscn.com the earliest Network Management Forum in China

</Parameter>
</Resourceparams>
<Resource type = "javax. SQL. datasource" name = "JDBC/zydb"/>
<Resourceparams name = "JDBC/zydb">
<Parameter>
<Name> URL </Name>
<Value> JDBC: oracle: thin: @ 10.0.0.168: 1521: zydb </value>
</Parameter>
<Parameter>
<Name> password </Name>
<Value> jckjdkmcj </value>
</Parameter>
<Parameter>
<Name> maxactive </Name> play.bitscn.com games
<Value> 4 </value>
</Parameter>
<Parameter>
<Name> maxwait </Name>
<Value> 5000 </value>
</Parameter>
<Parameter>
<Name> driverclassname </Name>
<Value> oracle. JDBC. Driver. oracledriver </value>
</Parameter>
<Parameter>
<Name> username </Name>
<Value> zhangyi </value>
</Parameter>

Feedom.net, the earliest website administrator in China

<Parameter>
<Name> maxidle </Name>
<Value> 2 </value>
</Parameter>
</Resourceparams>
</Context> Search for so. B

It

4. If you are developing in eclipse or JBuilder, You need to register the data source in the WEB-INF/Web. xml file of your web application. Add the following content to the file:
<Resource-ref>
<Res-ref-Name> JDBC/northwind </RES-ref-Name>
<Res-type> javax. SQL. datasource </RES-type>
<Res-auth> container </RES-auth>
</Resource-ref>
Note: Check the corresponding
The color bold text is added to register the JNDI of the data source. Here I have registered two data sources: Oracle and MSSQL Server 2000.

During any configuration, it is best not to modify any files on the Tomcat server, such as servel. XML or web. XML file, and all the operations and configurations can be completed in your own application configuration file, so that even if the cultivation of errors will not cause the server to crash.

Follow these steps to complete data source configuration. You can write some programs to test the data source.
Use JSP for testing. The index. jsp file program is as follows:

09hr.com Network Administrator job

<% @ Page Language = "Java" Import = "Java. util. *" %>
<% @ Page import = "javax. SQL. *" %>
<% @ Page import = "Java. SQL. *" %>
<% @ Page import = "javax. Naming. *" %>

<%
String Path = request. getcontextpath ();
String basepath = request. getscheme () + ": //" + request. getservername () + ":" + request. getserverport () + path + "/";
Out. println (basepath );
%>

<! Doctype HTML public "-// W3C // dtd html 4.01 transitional // en">
<HTML>
<Head>
<Base href = "<% = basepath %>">

<Title> my JSP 'index. jsp 'starting page </title>

<Meta http-equiv = "Pragma" content = "no-Cache"> bitscn. Net China Network Management blog
<Meta http-equiv = "cache-control" content = "no-Cache">
<Meta http-equiv = "expires" content = "0">
<Meta http-equiv = "keywords" content = "keyword1, keyword2, keyword3">
<Meta http-equiv = "Description" content = "this is my page">

<! --
<LINK rel = "stylesheet" type = "text/CSS" href = "styles.css">
-->
</Head>

<Body>
This is my JSP page. <br>

<%
Context CTX = NULL; play.bitscn.com games
Connection CNN = NULL;
Java. SQL. Statement stmt = NULL;
Resultset rs = NULL;
Try
{
CTX = new initialcontext ();
If (CTX = NULL)
Throw new exception ("initialize the context failed ");
Datasource DS = (datasource) CTX. Lookup ("Java: COMP/ENV/jdbc/northwind ");
Out. println (DS );
If (DS = NULL)
Throw new exception ("datasource is null ");

Try {
CNN = Ds. getconnection ();
Out. println ("<br> connection:" + CNN); Search so.bitscn.com
} Catch (exception e ){
E. printstacktrace ();
}

}
Finally
{
If (RS! = NULL)
Rs. Close ();
If (stmt! = NULL)
Stmt. Close ();
If (CNN! = NULL)
CNN. Close ();
If (CTX! = NULL)
CTX. Close ();
}


%>
</Body>
</Html>
Run http: // 10.0.0.168: 8888/webdemo/web/in your browser. The result is as follows:
 
 
When you see the mark of successful connection, it means that your data source is successfully configured !!!

Remember: to make the configuration successful, you must carefully check every detail of the configuration. Scn.com

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.