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!