Tomcat data source configuration method_jbuilder

Source: Internet
Author: User

In fact, there are several ways to configure the data source in tomcat, which is flexible, so they are easy to integrate with each other. In my opinion, the simple method is to add server. xml in the conf folder under tomcat. Copy codeThe Code is as follows: <Context path = "/test" docBase = "test"
Debug = "99" reloadable = "true" crossContext = "true" verbosity = "DEBUG">
<Resource name = "jdbc/***" auth = "Container"
Type = "javax. SQL. DataSource" password = "****"
DriverClassName = "com. microsoft. jdbc. sqlserver. SQLServerDriver"
MaxIdle = "2"
MaxWait = "5000"
Username = "sa"
Url = "jdbc: microsoft: sqlserver: // 192. 168. *. *: 1433; DatabaseName = ***"
MaxActive = "4"/>
</Context>

Note that it is added before After the server. xml file of tomcat is changed, a reference is added to the web. xml file in your web project.Copy codeThe Code is as follows: <resource-ref>
<Description> Resource reference to a factory for java. SQL. Connection
Instances that may be used for talking to a participant
Database that is configured in the server. xml file. </description>
<Res-ref-name> jdbc/*** </res-ref-name>
<Res-type> javax. SQL. DataSource </res-type>
<Res-auth> Container </res-auth>
</Resource-ref>

You only need to modify these two places to use the data source provided by tomcat in the web program. But in this way, you can run the war package you generated under the container, but cannot start the project in jbuilder, because jbuilder does not read the server in your specified tomcat when starting the web Project. in this case, the data source is not available. If we cannot start the project in jbuilder, we cannot run the program in the debugging status, this will not make much sense for us to write programs (of course, we can start tomcat outside and adopt remote debugging, so that we can use the data source or debug and modify the program, but this is a bit of a killer, which is not recommended). In fact, when jbuilder starts a web project, it will create a tomcat file shelf under the project directory, it will read the server8080.xml file under conf (8080 is the port you set for tomcat), so to start the data source in jbuilder, you must add the data source information in this configuration file ), specifically, delete a comment in server8080.xml (otherwise it will still be a temporary file and will be overwritten) in the Copy codeThe Code is as follows: <Resource name = "jdbc/***" auth = "Container"
Type = "javax. SQL. DataSource" password = "****"
DriverClassName = "com. microsoft. jdbc. sqlserver. SQLServerDriver"
MaxIdle = "2"
MaxWait = "5000"
Username = "sa"
Url = "jdbc: microsoft: sqlserver: // 192. 168. *. *: 1433; DatabaseName = ***"
MaxActive = "4"/>

Note that the <context> node is available for itself. do not modify the node and restart the project. Then you can use the data source. The reason why it is a little troublesome to start a web project in jbuilder is that it did not publish the project to the tomcat webapp, but took some of tomcat's items (equivalent ), like eclispe or idea.
The configuration data source mentioned above is tested in tomcat5.5.9. It is estimated that 5.5.x should be of no problem. If other tomcat versions are not guaranteed, who is calling us an Open Source Dongdong, version compatibility is not a compliment!

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.