日期:2014-05-16 浏览次数:20454 次
<Context> <!-- Default set of monitored resources --> <WatchedResource>WEB-INF/web.xml</WatchedResource> <!-- Uncomment this to disable session persistence across Tomcat restarts --> <!-- <Manager pathname="" /> --> <Resource name="jcptDataSourceJNDI" auth="Container" type="javax.sql.DataSource" username="tysp" password="12345678" driverClassName="oracle.jdbc.driver.OracleDriver" url="jdbc:oracle:thin:@192.168.1.52:1521:fuxing"/> <!-- Uncomment this to enable Comet connection tacking (provides events on session expiration as well as webapp lifecycle) --> <!-- <Valve className="org.apache.catalina.valves.CometConnectionManagerValve" /> --> </Context>
<welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list> <resource-ref> <description>Database Source</description> <res-ref-name>jcptDataSourceJNDI</res-ref-name> <res-type>javax.sql.DataSource</res-type> <res-auth>Container</res-auth> </resource-ref>
<body> <% Context initContext = new InitialContext(); Context envContext = (Context)initContext.lookup("java:/comp/env"); DataSource ds = (DataSource)envContext.lookup("jcptDataSourceJNDI"); Connection conn = ds.getConnection(); if(conn==null){ out.println("连接失败!"); }else{ out.println("连接成功!"); } Statement stmt = conn.createStatement(); ResultSet rs = stmt.executeQuery("select * from t_sys_dept"); while(rs.next()){ out.println("第一列:"+rs.getString(1)); } %> </body>