在Web应用中使用XML文件配置数据源
来源: 时间:06-12-30 点击: 点击这里收藏本文
<title>My JSP 'oracleDataSourceDemo.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>
<body>
This is my JSP page. <br>
this is a test of getting the connection
from a orace datasource configured using the XML files
<br>
<%
Context ctx=new InitialContext();
DataSource ds=(DataSource)ctx.lookup(OracleDataSourceListener.JNDI_NAME);
Connection con=ds.getConnection();
out.println(con);
%>
</body>
</html>
(八) 测试结果
(1) MSSQL 的测试结果为:
This is my JSP page.
this is a test of getting the connection from a orace datasource configured using the XML files
oracle.jdbc.driver.OracleConnection@143073a
(2) Oracle的测试结果为:
This is my JSP page.
org.apache.commons.dbcp.PoolableConnection@18facfb
以上程序均调试通过。如果还有问题,和我联系
zhyiwww@163.com.
总结:
(1) 编写数据源配置文件??XML文件
(2) 编写解析类
(3) 编写侦听器类
(4) 在Web.xml中配置数据源
(5) 测试数据源
在本例中,仅仅谈到实现,不涉及到其设计问题。仅供参考。
把此文章收藏到: