标签:style blog io ar color os 使用 sp java
1、编写context.xml 文件复制到 WebRoot/META_INF/context.xml
<?xml version=‘1.0‘ encoding=‘utf-8‘?> <Context> <WatchedResource>WEB-INF/web.xml</WatchedResource> <Resource name="jdbc/oracle" auth="Container" type="javax.sql.DataSource" driverClassName="oracle.jdbc.OracleDriver" url="jdbc:oracle:thin:@localhost:1521:orcl" username="system" password="FengZe2012" maxActive="1000" maxIdle="30" maxWait="10000" /> </Context>
2、复制相关的数据库jar文件到 WebRoot/WEB-INF/lib/目录下
3、 使用连接代码
<%@page import="java.sql.PreparedStatement"%> <%@ page language="java" pageEncoding="utf-8"%> <%@ page import="javax.naming.InitialContext"%> <%@ page import="javax.naming.Context"%> <%@ page import="javax.sql.DataSource"%> <%@ page import="java.sql.Connection"%> <% Context ctx = new InitialContext(); DataSource ds = (DataSource)ctx.lookup("java:/comp/env/jdbc/oracle"); Connection conn = ds.getConnection(); PreparedStatement pst = conn.prepareStatement("create table t(t number)"); pst.execute(); pst.close(); conn.close(); out.print(conn); %>
标签:style blog io ar color os 使用 sp java
原文地址:http://www.cnblogs.com/Dreamlu/p/4151545.html