oracle的JDBC連接

package com.xian.jdbc;

創(chuàng)新互聯(lián)是一家集網(wǎng)站建設(shè),容縣企業(yè)網(wǎng)站建設(shè),容縣品牌網(wǎng)站建設(shè),網(wǎng)站定制,容縣網(wǎng)站建設(shè)報(bào)價(jià),網(wǎng)絡(luò)營(yíng)銷,網(wǎng)絡(luò)優(yōu)化,容縣網(wǎng)站推廣為一體的創(chuàng)新建站企業(yè),幫助傳統(tǒng)企業(yè)提升企業(yè)形象加強(qiáng)企業(yè)競(jìng)爭(zhēng)力。可充分滿足這一群體相比中小企業(yè)更為豐富、高端、多元的互聯(lián)網(wǎng)需求。同時(shí)我們時(shí)刻保持專業(yè)、時(shí)尚、前沿,時(shí)刻以成就客戶成長(zhǎng)自我,堅(jiān)持不斷學(xué)習(xí)、思考、沉淀、凈化自己,讓我們?yōu)楦嗟钠髽I(yè)打造出實(shí)用型網(wǎng)站。

import java.sql.Connection;

import java.sql.DriverManager;

import java.sql.PreparedStatement;

import java.sql.ResultSet;

import java.sql.SQLException;

import javax.servlet.jsp.jstl.sql.Result;

import javax.servlet.jsp.jstl.sql.ResultSupport;

public class OracleConnection {

/**

* 連接ora數(shù)據(jù)庫(kù)

* @return con

* @throws ClassNotFoundException

* @throws SQLException

* @author 賈小仙

*/

   public static Connection getOracleConnection() throws ClassNotFoundException,SQLException{

  String driver="oracle.jdbc.driver.OracleDriver";

  String url="jdbc:oracle:thin:@127.0.0.1:1521:orcl";

  Class.forName(driver);

  Connection con=DriverManager.getConnection(url, "scott","7758521");

  return con;

   }

   /**

* 關(guān)閉ora連接通道

* @return 

* @throws SQLException

* @author 賈小仙

*/

   public void freeResources(ResultSet resultSet,PreparedStatement pStatement,Connection con) throws SQLException{

  if(resultSet.isClosed()==false)

  resultSet.close();

  if(pStatement.isClosed()==false)

  pStatement.close();

  if(con.isClosed()==false)

  con.close();

   }

   /**

  * 查詢無參數(shù)的Sql

  * @return Result

  * @throws Exception

  * @author 賈小仙

  */

   public Result runSelectSql(String sql){

  Connection con=null;

  PreparedStatement pStatement=null;

  ResultSet resultSet=null;

  Result result=null;

  try {

con=getOracleConnection();

pStatement=con.prepareStatement(sql);

resultSet=pStatement.executeQuery();

result=ResultSupport.toResult(resultSet);

} catch (Exception e) {

// TODO Auto-generated catch block

e.printStackTrace();

}finally{

try {

freeResources(resultSet, pStatement, con);

} catch (SQLException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

}

  return result;

   }

   /**

* 查詢有參數(shù)的Sql

* @return Result

* @throws Exception

* @author 賈小仙

*/

   public Result runSelectSql(String sql,Object[] params){

  Connection con=null;

  PreparedStatement pStatement=null;

  Result result=null;

  ResultSet resultSet=null;

  try {

con=getOracleConnection();

pStatement=con.prepareStatement(sql);

for(int i=0;i<params.length;i++){

pStatement.setObject(i+1, params[i]);

}

resultSet=pStatement.executeQuery();

result=ResultSupport.toResult(resultSet);

} catch (Exception e) {

// TODO Auto-generated catch block

e.printStackTrace();

}finally{

try {

freeResources(resultSet, pStatement, con);

} catch (SQLException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

}

  return result;

   }

}

分享文章:oracle的JDBC連接
文章路徑:http://bm7419.com/article12/pscgdc.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供微信小程序、定制網(wǎng)站、手機(jī)網(wǎng)站建設(shè)自適應(yīng)網(wǎng)站、軟件開發(fā)網(wǎng)站導(dǎo)航

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)

商城網(wǎng)站建設(shè)