Some things are used to learn, and sometimes I have forgotten it for a long time after I have been going to school. When I go to school, my teacher has a saying. It is better to make a pen, it seems to be a pen, even if it is very simple. Things, the time has been blurred, so I still write her down.
For the version below Tomcat5.0, the configuration database connection pool is about a few steps:
First, add the database configuration code in the Tomcat / conf / server.xml file, because Tomcat is managed through the server.xml file, in the server.xml file,
After opening the server.xml file, find the last context> tag, and then add the following paragraph, in the server.xml file
For these parameters, everyone should know what it means, but I want to say path = "/ demo" and docBase = "f: / project / igsnrr_proj / authorization_demo / webcontent", PATH: Remember the name of the original root of the application Anti-"" / "slash
DOCBASE: Refers to the directory where the application is released. If the published application directory is in Tomcat / WebApps /, then it is directly written to the name of the application, such as "WebContent"
Second, write a JSP test connection
After the configuration is configured above, you can write a JSP page test, I give the Java code that is connected:
public static synchronized Connection getConnection () {DataSource datasource; Connection connection; try {InitialContext initialcontext = new InitialContext (); Context context = (Context) initialcontext.lookup ( "java: comp / env"); datasource = (DataSource) context. Lookup ("JDBC / OSWF"); connection = DataSource.getConnection ();} catch (exception e) {system.out.println ("ConnectionPool - Initialization Database Exception!" E.getMessage ())} Return Connection; }
For the version after Tomcat5.0, the configuration connection pool is also the same, but 5.0 is better later, you can separate the configuration files of different applications, which we are placed in a unified system configuration file, after 5.0 You can write an XML file separately.
The directory structure is as follows:
Tomcat5.0 / conf / Catalina / Localhost /
In this directory, create a new XML file, such as ConnectTest.xml, and then copy the piece of the code above the connection pool to this file, 5.0 is the separation of the application configuration and system file configuration.
Ok, about the configuration of the database connection pool in Tomcat is over, if I find that I have a wrong place, please let me know. Thank you.