调用weblogic9数据源代码


package lhm.hcy.frameset.db;

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

/**
* <p>Title: Connection public class</p>
*
* <p>Description: </p>
*
* <p>Copyright: Copyright (c) 2008</p>
*
* <p>Company: </p>
*
* @author Deepblue 2009-11-20
* @version 1.0
*/

public abstract class Conndb {
String LOCATION_URL=null;
static String JNDI_DS_NAME=null;
ResourceBundle bundle = null;
private static Hashtable ht = null;

private Hashtable getHt(){
if (ht == null) {
ht = new Hashtable();
if (bundle == null) {
//JAVA读取配置文件, lhm.hcy.frameset.db 为properties文件的路径,jndi为文件名,后缀名可省略
bundle = ResourceBundle.getBundle("lhm.hcy.guge.frameset.db.jndi");
this.LOCATION_URL = bundle.getString("url");
this.JNDI_DS_NAME = bundle.getString("datasourcename");
}
ht.put(Context.INITIAL_CONTEXT_FACTORY,"weblogic.jndi.WLInitialContextFactory");
ht.put(Context.PROVIDER_URL,this.LOCATION_URL);
}
return ht;
}

protected Connection conn = null;
public void execute() throws SQLException {
Context ctx = null;

try {
ctx = new InitialContext(getHt());
javax.sql.DataSource ds = (javax.sql.DataSource)ctx.lookup(this.JNDI_DS_NAME);
conn = ds.getConnection();
conn.setAutoCommit(false);
myexecute();
conn.commit();
} catch(SQLException sex){
sex.printStackTrace();
}catch (Exception ex) {
ex.printStackTrace();
} finally {
if (conn!=null){
conn.close();conn=null;
}
}
}

/**
* myexecute
*/
public abstract void myexecute() throws SQLException;
}


============================================
jndi.properties文件如下:

url=t3:127.0.0.1:80
datasourcename=myDS
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值