放到 中。 二、F:\soft\apache-tomcat-5.5.23\conf\Catalina\localhost目錄中建立一個工程名.xml檔案,F:\soft\apache-tomcat-5.5.23為tomcat安裝目錄。在工程名.xml中寫下面的内容: 三、添加資料庫驅動jar檔案到F:\soft\apache-tomcat-5.5.23\common\lib與工程web目錄\lib下. 四、寫jsp頁面測試:
DataSource ds = null;
Connection conn = null;
ResultSet rs = null;
Statement stmt = null;
InitialContext ctx = null;
try {
ctx = new InitialContext();
ds = (DataSource) ctx.lookup("java:comp/env/jdbc/myown");
conn = ds.getConnection();
stmt = conn.createStatement();
rs = stmt.executeQuery("select * from users");
while (rs.next()) {
out.println(rs.getString(1) + "");
out.println(rs.getString(2) + "");
}
} catch (Exception ex) {
ex.printStackTrace();
} finally {
try {
if (rs != null)
rs.close();
if (stmt != null)
stmt.close();
if (conn != null)
conn.close();
if (ctx != null)
ctx.close();
} catch (SQLException e) {
System.out.println("SQL關閉異常");
e.printStackTrace();
} catch (NamingException e) {
System.out.println("命名空間關閉異常");
e.printStackTrace();
}
}
%>
分享到:
2008-01-07 16:23
浏覽 2451
評論
2 樓
qingfeng825
2008-01-07
第二種方式:直接在server.xml中配置應用即可,要入到中間,這種方式比較适合最後往伺服器上布署的時候,比較簡單,隻需要一個地方配置即可.
auth="Container"
type="javax.sql.DataSource"
maxActive="10"
maxIdle="3"
maxWait="10000"
username="FASHIMIS"
password="FASHIMIS" driverClassName="oracle.jdbc.driver.OracleDriver"
url="jdbc:oracle:thin:@192.168.0.230:1521:ora92"/>
1 樓
qingfeng825
2008-01-07
如果接oracle隻需把相應的jar 包拷上,把配置檔案改為:
auth="Container"
type="javax.sql.DataSource"
maxActive="10"
maxIdle="3"
maxWait="10000"
username="FASHIMIS"
password="FASHIMIS" driverClassName="oracle.jdbc.driver.OracleDriver"
url="jdbc:oracle:thin:@192.168.0.230:1521:ora92"/>