MySQL - Connector J - Tomcat
About MySQL Connector J - Tomcat
Tomcat10環境を想定 調整する設定ファイルは context.xml, webapps WEB-INF下のweb.xml
file:%TOMCAT_HOME%\conf\context.xml
<Context>
<!-- 追加 -->
<Resource name="jdbc/RefMySQLDB" auth="Container" type="javax.sql.DataSource"
maxTotal="100" maxIdle="30" maxWaitMills="10000"
username="username" password="password" driverClassName="com.mysql.cj.jdbc.Driver"
url="jdbc:mysql://localhost:3306/java_env"
/>
</Context>
file:%TOMCAT_HOME%\webapps\examples\WEB-INF\web.xml
<web-app xmlns省略
<!-- 追加 -->
<resource-ref>
<description>DB Connection for MySQL</description>
<res-ref-name>jdbc/RefMySQLDB</ref-res-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
利用例
<sql:query var="rs" dataSource="jdbc/RefMySQLDB">
select id, title from test_data
</sql:query>
<html>
<body>
<h2>Result</h2>
<c:forEach var="row" items="${rs.rows}">
Id ${row.id}<br />
Title ${row.title}<br />
</c:forEach>
</body>
</html>>