resin使用mysql的JNDI数据源

来源:互联网 发布:手机进程清理软件 编辑:程序博客网 时间:2024/05/21 11:05
1.配置conf/resin.conf文件,在

<resource-ref>
  
<res-ref-name>jdbc/test</res-ref-name>
  
<res-type>javax.sql.DataSource</res-type>
  
<init-param driver-name="com.caucho.jdbc.mysql.Driver"/>
  
<init-param url="jdbc:mysql_caucho://localhost:3306/test"/>
  
<init-param user=""/>
  
<init-param password=""/>
  
<init-param max-connections="20"/>
  
<init-param max-idle-time="30"/>
</resource-ref>

下输入自己的数据库配置 

<resource-ref>
  
<res-ref-name>jdbc/pms</res-ref-name>
  
<res-type>javax.sql.DataSource</res-type>
  
<init-param driver-name="com.mysql.jdbc.Driver"/>
  
<init-param url="jdbc:mysql://server:3306/pms"/>
  
<init-param user="username"/>
  
<init-param password="password"/>
  
<init-param max-connections="20"/>
  
<init-param max-idle-time="30"/>
</resource-ref>

2.编写test.jsp文件,显示node表的前两个字段数据:

<%@ page import='java.sql.*, javax.sql.*, javax.naming.*' %>
<%
Context ic 
= new InitialContext();
DataSource ds 
= (DataSource) ic.lookup("java:comp/env/jdbc/pms");

Connection conn 
= ds.getConnection();

try {
  Statement stmt 
= conn.createStatement();
  ResultSet rs 
= stmt.executeQuery("select * from node");
  
while (rs.next()) { %>
<%= rs.getString(1%> <%= rs.getString(2%><br><%
  }
finally {
  conn.close();
}
%>

3.在ibatis的sql-map-config.xml进行jndi配置

  <transactionManager type="JDBC">
    
<dataSource type="JNDI"> 
        
<property name="DataSource" value="java:comp/env/jdbc/pms"/>
    
</dataSource> 
  
</transactionManager>
原创粉丝点击