Add the following to the <context> node in the tomcat_home/CONF/context. xml file:
<Resource
Name = "JDBC/SQL"
Auth = "Container"
Type = "javax. SQL. datasource"
Maxactive = "100"
Maxidle = "30"
Maxwait = "10000"
Username = "root"
Password = "root"
Driverclassname = "com. MySQL. JDBC. Driver"
Url = "JDBC: mysql: // localhost: 3306/test"
/>
Attribute explanation:
Name: Data Source Name Auth: Permission type: Type
Maxactive: Maximum number of connections to the database. Set 0 to no limit.
Maxidle: Maximum number of waiting connections. Set 0 to no limit.
Maxwait: Maximum number of waiting milliseconds, measured in MS, error messages are generated when the time exceeds
Add
<Resource-ref>
<Description> dB connection </description>
<Res-ref-Name> JDBC/SQL </RES-ref-Name>
<Res-type> javax. SQL. datasource </RES-type>
<Res-auth> container </RES-auth>
</Resource-ref>
Obtain the connection method in the project:
context initcontext = new initialcontext ();
context envcontext = (context) initcontext. lookup ("Java:/COMP/ENV");
datasource DS = (datasource) envcontext. lookup ("JDBC/SQL");
connection conn = Ds. getconnection ();
statement ST = NULL;
resultset rs = NULL;
ST = Conn. createstatement ();
rs1_st.exe cutequery (SQL);