版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)
文檔簡介
1、j2ee應(yīng)用中與oracle數(shù)據(jù)庫的連接connection to the oracle database in j2ee applicationsin j2ee application development, the creation of applications and database connections is one of the problems we often encounter. here i mainly talk about in the local application way by oci, thin and jdbcodbc bridge connectin
2、g oracle database, the iplanet application server 6. 5 and sun java system application server 7 configuration and application of the oracle database connection pool to obtain a connection from the connection poolthe oracle database connection is obtained locally through jdbcthere are three ways to g
3、et an oracle database connection through jdbc: oci, thin, and jdbcodbc bridge the oci approach relies on the local dynamic link library, which can be used if the oracle database die nt is installed locall y. the thin method is a database connection for pure java; the jdbcodbc bridge approach relies
4、on the configuration of the local odbc database source, which is generally not adopted.1, oci waythe oracle client is installed locally, and after the installation, you can find it in the installstion path / jdbc/lib/classes12.zip file, we set the path of classesl2.zip in the environment variable cl
5、asspaththe oracle database connection is obtained locally through the oci method through the following database connection class* get the database connection locally* /package com j2ee.import javaimport javaimport javax sql.import javaimport oracleimport javax/ * * get the oracle database connection
6、 through oci* /public class dbconnectionfindl static string sdbdriver = "oracle, driver.final static string sconnstr 二 jdbc: oracle: oci8: sr/sr oral99/,/ * * /public dbconnection ()/ * * get the oracle database connection* /public java.sql. connection connectdbbyoci ()java. sql. connection cor
7、m 二 null;the tryclass forname (sdbdriver);conn 二 drivermanager getconnection (sconnstr);catch (exception e)( error:")return the conn.in the connection string "jdbc: oracle: oci8: sr/sr oral99,z, the sr/sr" user name and password for oracle users, ,oral99,/ for the database service nam
8、e2, thin wayfirst to the oracle technology network(http:/otn.oracle com/global/cn/software/tech/java/sqlj_jd be/indexhtml) to download the oracle jdbc drivers, likewise after downloading the zip file path set in the classpath environment variablethe oracle database connection is then obtained locall
9、y through the thin method locally via the following database connection class./ * * get the database connection locally* /package com j2eeimport javaimport javaimport javax sql.import javaimport oracleimport javax/ * * * get the oracle database connection through thinpublic class dbconnectionprivate
10、 string sconnstr 二"“;/ * * default constructor* /public dbconnection ()sconnstr 二 jdbc: oracle: thin: 10.1. 4.199: oral99;/ * * param ip, servicename* /public dbconnection (string ip, string servicename)sconnstr 二 jdbc: oracle: thin:+ ip + : 1521: +servicename;* get the connection to the oracle
11、 database through thin.* /public java. sql. connection connectdbbythin ()java. sql. connection conn = null;the tryclass forname (sdbdriver);conn 二 drivermanager, getconnection (sconnstr,/z sr "、sr);catch (exception e)( error: /z)return the conn./ * * get the connection to the oracle database th
12、rough thin.* param userid, password* /public java sql. connection connectbyjdbc (string userid,string password)javasql. connection conn = null;the tryclass forname (sdbdriver);drivermanager getco rm ection (sconnstr, userid, password);catch (exception e)( error:')return the connthis approach is
13、flexible, simple, with a strong portability and applicability as long as you are aware of the connection string "jdbc: oracle: thin: 10. 1. 4. 199:1521: oral99,z, the specific parameters are set3, jdbcodbc bridge modefirst through management tools in the data source to add local oracle database
14、 connection, and then through the following database connection class, locally by jdbcodbc bridge for oracle database connection.* get the database corm ection locally * /package com j2eeimport javaimport java.import javax sql.import javaimport oracleimport javax/ * * get the oracle database corm ec
15、tion through the jdbcodbcbridge* /public class dbconnection* /public dbconnection ()/ * * get the oracle database connection* /public javasql. connection connectdbcbridge ()java. sql. connection conn 二 null;the tryforname (“ sun. jdbcdbcdriver “);con 二 drivermanagergetconnection (“ jdbc: ora199 “, s
16、r );catch (exception e)( error:")return the conn.the first parameter in the getconnection method jdbc: odbc: oral99,/ in the ,oral99,/ for local odbc data source and data source name, the second and third parameters respectively as the oracle user name and passwordthe oracle database connection
17、 is obtained through the connection poolthis part focuses on the iplanet application server 6. 5 and sun java system application server 7 oracle database connection pool configuration, and how to use the connection pool in the application of the database connection.the iplanet application server 6.5
18、 connection pool configurationopens first iplanet 6.5 application server admin console, select "database" panel, and then select "external jdbc drivers" option, click "add"button, in the pop-up dialog box, add a jdbc driver called "ora - type4"driver classpath
19、: this parameter fills the physical path of the classesl2. zip file.then select add"in the ''external jdbc datasources,z and adda jndi name box.to the z,credit2,z data source in the pop-up dialogdrivertype:select "ora type4;datasource:oral99, for oracle database service name;dataso
20、urce:oral99, for oracle database service name;connection pool parameters: the default settings are shown in the diagram, which can be changed depending on your environmentafter save the settings, the ''datasource selection box,choose just added credit2 data source, and select "vendor sp
21、ecific properties" button. add a url attribute to the conversation.at this point, the database connection pool in the iplanet application server 6.5 has been configured and the service is reconfigured to take effectthe sun java system application server 7 connection pool configurationplace the
22、classesl2.zip file before configuring / server1 / lib directory. through the browser open port 4848 sun java system application server management interface, select "serverl" 一 > jdbc 一 > "'connection pools" under the "newadd an oracle database connection pool calle
23、d "myconnectionpoo1"next" nextfill in the ''datasource classname,z in ''generaldelete the attributes that you don,t need in "properties" and add "url" properties/,datasourcename,/ fills in the oracle database service namethe following connection poo
24、t s default settings can be adjusted according to the circumstances of your environmentselect "finish" to complete the connection pool settingsthe next step is to create a jndi for the ,zmyconnectionpoo 1 connection pool so that the application can get the connection in the connection pool
25、 through the name"serverl" - > "jdbc" -> "jdbc resources" under "new."at this point, the database connection pool in the sun java system application server7 has been configured and the service has been reconfigured to take effectget the connection throug
26、h the connection poolabove in iplanet application server 6.5 and sun java system application server7 configured in the connection pool can be covered by the following database connection class, oracle database connection from the connection pool./ * * get the database connection from the connection pool* /package com j2eeimport javaimport javaimport javax sql.import the java 10.*;import oracleimport javax* get the oracle database connection by connection poolingpublic class dbconnection* /public dbconnection ()* get the oracle database connection* /public java. sql. connect!on connectdbbyc
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 《簡筆畫上色技巧》課件
- 中心投影和平行投影課件
- 《壓力管理》課件
- 《市場營銷情景模擬》課件
- 單位管理制度集粹選集職工管理篇
- 單位管理制度匯編大全職員管理篇
- 單位管理制度合并選集人力資源管理篇
- 三峽復(fù)習(xí)課件
- 《精油的起源基礎(chǔ)》課件
- 單位管理制度分享合集【人事管理】
- 2025蛇年帶橫批春聯(lián)對聯(lián)200副帶橫批
- DZ/T 0462.3-2023 礦產(chǎn)資源“三率”指標(biāo)要求 第3部分:鐵、錳、鉻、釩、鈦(正式版)
- Lesson-1.-spring-festival(雙語課件-春節(jié))
- 大學(xué)學(xué)院成績單(模板)
- 奧林燃燒器說明書(GP130-150H)
- 績效管理模塊-績效管理與績效考核制度
- 《工人工資發(fā)放承諾書范文 》
- 馬達(dá)加斯加 礦產(chǎn)和能源開發(fā)戰(zhàn)略
- 忘憂草(周華健)原版五線譜鋼琴譜正譜樂譜.docx
- 一年級必背古詩(拼音版)
- 電氣設(shè)備事故處理規(guī)程
評論
0/150
提交評論