nibaba
发贴: 0
积分: 0
|
于 2003-07-18 17:31
在Oracle9iAS Containers for J2EE 1.0.2.2中使用oci8 driver查询oracle数据库时jsp页面无显示。我先修改config下的data-sources.xml如下所示: <?xml version="1.0"?> <!DOCTYPE data-sources PUBLIC "Orion data-sources" "http://xmlns.oracle.com/ias/dtds/data-sources.dtd">
<data-sources> <!-- An example/default DataSource that uses Oracle JDBC-driver to create the connections. This tag creates all the needed kinds of data-sources, transactional, pooled and EJB-aware sources. The source generally used in application code is the "EJB" one - it provides transactional safety and connection pooling. Oracle thin driver could be used as well, like below. url="jdbc:oracle:thinhost:port:sid" -->
<data-source class="com.evermind.sql.DriverManagerDataSource" name="OracleDS" location="jdbc/OracleCoreDS" xa-location="jdbc/xa/OracleXADS" ejb-location="jdbc/OracleDS" connection-driver="oracle.jdbc.driver.OracleDriver" username="workbrain" password="workbrain" url="jdbc:oracle:oci8puppy.www.chinatps.com" language="java" inactivity-timeout="30" />
</data-sources> jsp文件如下所示: <%@ page contentType="text/html; charset=shift_jis" %> <%@ page import="java.util.*" %> <%@ page import="java.text.*" %> <%@ page import="java.sql.*" %> <%@ page import="javax.sql.*" %> <%@ page import="javax.naming.*" %> <%@ page import="java.io.*" %>
<html> <head></head> <body> <h1>hello!</h1> <% Connection conn = null; Context ic = new InitialContext(); Statement sttSql = null; ResultSet rs = null; out.println("<font size=8 color=red>start!</font>"); try{ DataSource ds = (DataSource) ic.lookup("jdbc/OracleDS"); conn = ds.getConnection(); sttSql = conn.createStatement(); rs = sttSql.executeQuery("select emp_name from employee"); while(rs.next()){ out.println(rs.getString("emp_name") + "<br>"); } out.println("<font size=8 color=red> end! </font>"); } catch(Exception e){ out.println("<font size=8 color=red>error!</font>"); } rs.close(); sttSql.close(); conn.close(); ic.close(); %> </body> </html>
|