首先
create table BOOK(BOOK_CODE CHAR(
COST NUMBER(
插入幾條記錄:
insert into BOOK valueS(B
insert into BOOK valueS(B
……
tomcat安裝路徑為D:\tomcat
D:\tomcat
|
|
|
現在開始為DBCP做准備工作
下面開始配置xml文件
用(你習慣的)文本編輯器打開D:\tomcat
下面就是寫一個JSP代碼進入測試了
在D:\tomcat
<%@ page import="javax.naming.Context" %>
<%@ page import="javax.sql.DataSource"%>
<%@ page import="javax.naming.InitialContext"%>
<%@ page import="java.sql.*"%>
<%
DataSource ds = null;
try{
Context initCtx = new InitialContext();
Context envCtx = (Context) initCtx.lookup("java:comp/env");
ds = (DataSource)envCtx.lookup("jdbc/myoracle");
if(ds!=null){
out.println("Connection is OK!");
Connection cn=ds.getConnection();
if(cn!=null){
out.println("cn is Ok!");
Statement stmt = cn.createStatement();
ResultSet rst = stmt.executeQuery("select * from BOOK");
out.println("
rst is Ok!" + rst.next());
while(rst.next()){
out.println("
BOOK_CODE:" + rst.getString(1));
}
cn.close();
}else{
out.println("rst Fail!");
}
}
else
out.println("Fail!");
}catch(Exception ne){ out.println(ne);
}
%>
最後
From:http://tw.wingwit.com/Article/program/Java/ky/201311/28355.html