這是我在項(xiàng)目當(dāng)中積累的資料關(guān)于配置tomcat和 weblogic的數(shù)據(jù)源,貼出來和大家分享,有什么問題還請(qǐng)多指教,共同學(xué)習(xí),共同進(jìn)步
一、tomcat數(shù)據(jù)源的配制
★★注意將數(shù)據(jù)庫驅(qū)動(dòng)程序最好放在common里,tomcat最先加載這里的驅(qū)動(dòng),放在server里有時(shí)候會(huì)出現(xiàn)找不到驅(qū)動(dòng)程序的錯(cuò)誤
在tomcat5.5中需要下載apache-tomcat-5.5admin.tar.rar 這個(gè)包才可以進(jìn)行配制
1.首先進(jìn)入tomcat的配制數(shù)據(jù)源的頁面Data Sources中配制jndi等連接信息如(jndi為hdb)
2.在自己應(yīng)用中的WEB-INF中的web.xml中添加如下:
<resource-ref>
<description>
Resource reference to a factory for java.sql.Connection
instances that may be used for talking to a particular
database that is configured in the server.xml file.
</description>
<res-ref-name>
hdb
</res-ref-name>
<res-type>
javax.sql.DataSource
</res-type>
<res-auth>
Container
</res-auth>
</resource-ref>
3.在META-INF中添加context.xml文件內(nèi)容如下:
<?xml version="1.0" encoding="UTF-8"?>
<Context>
<WatchedResource>WEB-INF/web.xml</WatchedResource>
<Resource name="hdb" auth="Container"
type="javax.sql.DataSource" username="wangwin" password="wangwin"
driverClassName="oracle.jdbc.driver.OracleDriver"
url="jdbc:oracle:thin:@127.0.0.1:1521:ora9"
maxActive="10" maxIdle="2"/>
</Context>
4.在程序中通過JNDI得到連接對(duì)象內(nèi)容如下:
try {
Context initCtx = new InitialContext();
Context envCtx = (Context) initCtx.lookup("java:comp/env");//這里這是必須的。。。
DataSource ds = (DataSource)(envCtx.lookup( "hdb" ));
if (ds != null){
Connection conn = ds.getConnection();//得到連接對(duì)象測(cè)試內(nèi)容
conn.setAutoCommit(false);
Statement stm = conn.createStatement();
ResultSet rs = stm.executeQuery("select * from tshp_flow");
while(rs.next()){
System.out.println(rs.getString(1));
System.out.println(rs.getString(2));
System.out.println(rs.getString(3));
}
}else{
}
} catch (NamingException ex) {
ex.printStackTrace();
}
二、weblogic數(shù)據(jù)源的配制
1.打開weblogic的控制臺(tái)-服務(wù)-JDBC-連接緩沖池 配制數(shù)據(jù)庫的連接信息
2.服務(wù)-JDBC-數(shù)據(jù)源創(chuàng)建JNDI-繼續(xù)-選擇剛剛配制好的數(shù)據(jù)庫JDBC
3.得到連接對(duì)象
只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。 | ||
![]() |
||
網(wǎng)站導(dǎo)航:
博客園
IT新聞
Chat2DB
C++博客
博問
管理
|
||
相關(guān)文章:
|
||