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:
jdbc/myDataSource javax.sql.DataSource
... url jdbc:mysql://localhost:3306/mydatabase username root password
... driverClassName com.mysql.jdbc.Driver maxActive 10 maxIdle 5
Context initContext = new InitialContext(); Context envContext = (Context) initContext.lookup("java:comp/env"); DataSource dataSource = (DataSource) envContext.lookup("jdbc/myDataSource");
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!