'JDBC'에 해당되는 글 1건

  1. [2009/11/19] WebLogic Connection Pool 사용하기

WebLogic Connection Pool 사용하기

[작렬허접코딩/자바]

웹로직 짜증난다.
T3 프로토콜 때문에 다른 Servlet Container에서 사용중인 DB Connection 및 RMI 통신 부분을 사용할 수 없게 되었다.

package kr.co.jinjin.jjxweb.sql;

import java.io.*;
import java.sql.*;
import java.util.*;
import javax.naming.*;

import kr.co.jinjin.jjxweb.conf.*;

public class WebLogicDBConnection extends AbstractDBConnection {
 private JJXWebConf xconf = null;
 private Properties poolProp = null;

 public Connection getPooledConnection(String poolName) throws Exception {
  synchronized(WebLogicDBConnection.class) {
   if(poolProp==null) {
    poolProp = new Properties();
    try {
     loadProperties();
    } catch(Exception ex) {
     ex.printStackTrace();
    }
   }
  }
 
  Connection conn = null;
  Context ctx = null;
 
  Hashtable ht = new Hashtable();
  ht.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory");
  // Load t3 protocol url from properties file
  //  ex) t3://127.0.0.1:7001
  ht.put(Context.PROVIDER_URL, poolProp.getProperty(poolName));
 
  ctx = new InitialContext(ht);
  javax.sql.DataSource ds = (javax.sql.DataSource) ctx.lookup(poolName);
  conn = ds.getConnection();

  return conn;
 }
 
 /**
  * Load weblogic.properties
  * @throws Exception
  */
 private void loadProperties() throws Exception {
  boolean debug = false;
  String confdir = null;
  String filename = "weblogic.properties";
  File curp = null;
  FileInputStream fis = null;
 
  try {
   xconf = JJXWebConf.getInstance();
  } catch(Exception ex) {}
  debug = new Boolean(xconf.get("debug")).booleanValue();
 
  confdir = xconf.get("homedir") + "conf" + File.separator;
  curp = new File(confdir + filename);
  if(!curp.exists())
   throw new Exception("Configuration file '/WEB-INF/conf/weblogic.properties' not found");
 
  if(debug) {
   System.out.println("# WebLogicDBConnection.loadProperties()");
   System.out.println("# Properties FileName : " + curp.getCanonicalPath());
  }
 
  try {
   //fis = new FileInputStream(curp);
   fis = new FileInputStream(curp.getCanonicalPath());
   poolProp.load(fis);
   
   if(debug)
    poolProp.list(System.out);
  } catch(Exception ex) {
   throw new Exception(ex);
  } finally {
   try {
    //if(fis!=null) fis.close();
   } catch(Exception ex) {}
  }
 }
 
}

다음은 weblogic.properties
jjxweb=t3://127.0.0.1:7011

이올린에 북마크하기(0) 이올린에 추천하기(0)
2009/11/19 23:28 2009/11/19 23:28