资源描述:
《j2ee应用中与oracle数据库的连接》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、J2EE应用中与Oracle数据库的连接ConnectiontotheOracledatabaseinJ2EEapplicationsInJ2EEapplicationdevelopment,thecreationofapplicationsanddatabaseconnectionsisoneoftheproblemsweoftenencounter.HereImainlytalkaboutinthelocalApplicationwaybyOCI,thinandJdbcOdbcbridgeconnect
2、ingOracledatabase,theiPlanetApplicationServer6.5andSunJavaSystemApplicationServer7configurationandApplicationoftheOracledatabaseconnectionpooltoobtainaconnectionfromtheconnectionpoolTheOracledatabaseconnectionisobtainedlocallythroughJDBCTherearethreewaysto
3、getanOracledatabaseconnectionthroughJDBC:OCI,thin,andJdbcOdbcbridge・TheOCIapproachreliesonthelocaldynamiclinklibrary,whichcanbeusediftheOracledatabasedientisinstalledlocally.ThethinmethodisadatabaseconnectionforpureJava;TheJdbcOdbcbridgeapproachreliesonthe
4、configurationofthelocalODBCdatabasesource,whichisgenerallynotadopted.1,OCIwayTheOracleclientisinstalledlocally,andaftertheinstallation,youcanfinditintheinstallstionpath・・・/JDBC/lib/classes12.zipfile,wesetthepathofclassesl2.zipintheenvironmentvariableclassp
5、ath・TheOracledatabaseconnectionisobtainedlocallythroughtheOCImethodthroughthefollowingdatabaseconnectionclass*getthedatabaseconnectionlocally*/Packagecom・j2ee.ImportJava・ImportJava・Importjavax・sql.ImportJava・Importoracle・Importjavax・/***gettheOracledatabas
6、econnectionthroughOCI*/PublicclassDbConnectionFindlstaticStringsDBDriver="oracle,driver.FinalstaticStringsConnStr二〃JDBC:oracle:oci8:sr/sr@oral99/,/****/PublicDbConnection(){}/***gettheOracledatabaseconnection*/Publicjava.sql.ConnectionconnectDbByOci(){Java
7、.sql.Connectioncorm二null;ThetryClass・forname(sDBDriver);Conn二drivermanager・getconnection(sConnStr);Catch(Exceptione)(〃ERROR:")Returntheconn.Intheconnectionstring"JDBC:oracle:oci8:sr/sr@oral99,z,〃thesr/sr"usernameandpasswordfororacleusers,,,oral99,/fortheda
8、tabaseservicename・2,thinwayFirsttotheOracletechnologynetwork(http://otn.oracle・com/global/cn/software/tech/java/sqlj_jdbe/index・html)todownloadtheOracleJDBCDrivers,likewiseafterdownloadingthezipfilepathsetint