配置:
在resin.conf文件中<server>标签内添加如下代码:
<database>
<jndi-name>jdbc/test</jndi-name>
<driver type="com.mysql.jdbc.Driver">
<url>jdbc:mysql://localhost:3306/test?autoReconnect=true&useUnicode=true&characterEncoding=utf-8&mysqlEncoding=utf8</url>
<user>root</user>
<password>111111</password>
</driver>
<prepared-statement-cache-size>20</prepared-statement-cache-size>
<max-connections>200</max-connections>
<max-idle-time>30s</max-idle-time>
</database>
jndi-name:用于查找该连接的JNDI名称
driver :jdbc驱动名称
url:连接的url
user:数据库用户名
password:密码
在Java代码中访问:
try {
DataSource ds=null;
InitialContext context=new InitialContext();
ds=(DataSource) context.lookup("java:comp/env/jdbc/test");
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
这个是前面学习openjpa的时候