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 >
< 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 >
< 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.*
'
%>
<%
Contextic = new InitialContext();
DataSourceds = (DataSource)ic.lookup( " java:comp/env/jdbc/pms " );
Connectionconn = ds.getConnection();
try {
Statementstmt = conn.createStatement();
ResultSetrs = stmt.executeQuery( " select*fromnode " );
while (rs.next()){ %>
<%= rs.getString( 1 ) %> <%= rs.getString( 2 ) %>< br ><%
}
} finally {
conn.close();
}
%>
<%
Contextic = new InitialContext();
DataSourceds = (DataSource)ic.lookup( " java:comp/env/jdbc/pms " );
Connectionconn = ds.getConnection();
try {
Statementstmt = conn.createStatement();
ResultSetrs = stmt.executeQuery( " select*fromnode " );
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 >
< dataSource type ="JNDI" >
< property name ="DataSource" value ="java:comp/env/jdbc/pms" />
</ dataSource >
</ transactionManager >