Server.
<Resource
name="jdbc/
MySQL"
ty
PE="javax.
SQL.DataSource"
password="******"
driver
classname="
org.gjt.mm.mysql.Driver"
max
idle="2"
maxW
ait="5000"
username="root"
url="jdbc:mysql://127.0.0.1/
test"
maxActive="4" />
<?xml version="1.0" encoding="UTF-8"?>
<Context>
<Resource
name="jdbc/mysql"
type="javax.sql.DataSource"
password="******"
driverClassName="org.gjt.mm.mysql.Driver"
maxIdle="2"
maxWa
IT="5000"
username="root"
url="jdbc:mysql://127.0.0.1/test"
maxActive="4" />
</Context>
,如果没有这步就会出错,会出现 org.
.tomcat.dbcp.dbcp.SQLNestedException: Cannot create JDBC driver of class '' for connect URL 'null'错误。
<resource-ref>
<description>DB Connection</description>
<res-ref-name>jdbc/mysql</res-ref-name>
<res
-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
DataSource ds = null;
InitialContext ctx = new InitialContext();
ds = (DataSource) ctx.lookup("java:comp/
env/jdbc/mysql");
Connection conn = ds.getConnection();