Tomcat data source configuration includes the following steps: Create the data source object (
element) Set the connection parameters (URL, user name, password) Bind the JDBC database (driver, connection pool implementation) in the code Use the data source (JNDI name) in
Required to configure the data source in Tomcat After the following steps:
Create a DataSource object:
web.xml
file # element to create a data source object.
Set connection parameters:
element , such as URL, username and password.
Bind JDBC database:
element Driver and connection pool implementation.
Use the data source in the application:
<code class="xml"><resource> <name>jdbc/myDataSource</name> <type>javax.sql.DataSource</type> </resource></code>
<code class="xml"><resource> ... <property> <name>url</name> <value>jdbc:mysql://localhost:3306/mydatabase</value> </property> <property> <name>username</name> <value>root</value> </property> <property> <name>password</name> <value></value> </property> </resource></code>
<code class="xml"><resource> ... <property> <name>driverClassName</name> <value>com.mysql.jdbc.Driver</value> </property> <property> <name>maxActive</name> <value>10</value> </property> <property> <name>maxIdle</name> <value>5</value> </property> </resource></code>
<code class="java">Context initContext = new InitialContext(); Context envContext = (Context) initContext.lookup("java:comp/env"); DataSource dataSource = (DataSource) envContext.lookup("jdbc/myDataSource");</code>
The above is the detailed content of How to configure data source in tomcat. For more information, please follow other related articles on the PHP Chinese website!