weblogic9.2不像低版本那样 有单独的配置连接池的地方 那我想用连接池获得连接该怎么办啊(除了用datasource)
我用这种代码是不是就获得不了连接了 Driver myDriver = (Driver) (Class.forName("weblogic.jdbc.pool.Driver").newInstance()); Connection con = myDriver.connect("jdbc:weblogic:pool:SQLSERVERPOOL", null);
我用这种代码是不是就获得不了连接了 Driver myDriver = (Driver) (Class.forName("weblogic.jdbc.pool.Driver").newInstance()); Connection con = myDriver.connect("jdbc:weblogic:pool:SQLSERVERPOOL", null);
解决方案 »
- KAnalyzer在tomcat下配置,IKAnalyzer.cfg.xml放置的路径问题
- 求要 Sql Server 2005 java 小例子
- spring security3 注销后保持原session?
- 上传了一个文件,为什么需要刷新文件才显示
- java.lang.NullPointerException
- 想问下进销存系统..公司里面建类用的是什么模式..用抽象工厂模式好吗?
- ejb
- 大哥大姐们,救命啊!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
- 群"j2ee without ejb"(18745267),欢迎大家交流
- 在xml中存在&,如何显示?
- 不能new一个在JAR中的CLASS,高手帮忙,多谢!
- 关于java中使用jacob调用c++写的ocx时参数传递的问题
http://blog.sina.com.cn/s/blog_5d31611a0100d0rx.htmlWebLogic9.2 + MS SQLServer2000连接池
http://bbs.chinaunix.net/thread-998833-1-1.htmlweblogic连接池配置
http://ytuwlg.javaeye.com/blog/270679
希望对你有帮助
import java.sql.*;
import javax.sql.*;
import javax.naming.*;
import java.io.*;
import java.util.*;
public class JDBCPoolDemo
{
public static void main(String args[])
{
String tablename="student"; //数据库中表名
String sqlstr; //sql语句
Connection con=null; //连接对象
Statement stmt=null; //语句对象
ResultSet rs=null; //结果集对象
Context ctx=null;
Hashtable ht=new Hashtable();
try
{
ht.put(Context.INITIAL_CONTEXT_FACTORY,"weblogic.jndi.WLInitialContextFactory");
ht.put(Context.PROVIDER_URL,"t3://localhost:7001");
// 创建一个初始上下文环境
ctx=new InitialContext(ht);
//查询weblogic server的JNDI名字服务,JNDI 会指明访问的数据源所在位置。DataSource 数据源与配置的名字是一样
DataSource ds=(DataSource)ctx.lookup("MysqlDataSource");
//利用DataSource调用getConnection()方法,获取数据库的配置信息。
con=ds.getConnection();
stmt=con.createStatement(); // 创建statement对象
sqlstr="select * from "+tablename; // 书写SQL语句
rs=stmt.executeQuery(sqlstr); // 执行SQL语句,返回查询结果
while(rs.next())
{
System.out.print(rs.getString("id"));
System.out.print("\t");
System.out.print(rs.getString("name"));
System.out.print("\t");
System.out.print(rs.getInt("age"));
System.out.print("\t");
System.out.print("\n");
}
}
catch(NamingException e1)
{
System.out.println(e1.toString());
System.out.println("驱动程序没有找到!");
}
catch(SQLException e2)
{
System.out.println(e2.toString());
System.out.println("数据库异常!");
}
finally
{
try
{
if(rs!=null) rs.close();
if(stmt!=null) stmt.close();
if(con!=null) con.close();
}
catch(Exception e)
{
System.out.println(e.toString());
}
}
}
}
Driver myDriver = (Driver) (Class.forName("weblogic.jdbc.pool.Driver").newInstance()); Connection con = myDriver.connect("jdbc:weblogic:pool:SQLSERVERPOOL", null);
我的意思是在weblogic9.2版本中没有配置连接池的jndi的地方 是不是意味着 weblogic9.2不能使用我上面这种方法进行数据库的连接 希望高手给个回答
Properties env=new Properties();
env.put(InitialContext.INITIAL_CONTEXT_FACTORY,"weblogic.jndi.WLInitialContextFactory");
env.put(InitialContext.PROVIDER_URL, url); //地址及端口号
env.put(InitialContext.SECURITY_PRINCIPAL, user);//登录到数据库的用名
env.put(InitialContext.SECURITY_CREDENTIALS, password);//密码
InitialContext ctx = new InitialContext(env);
DataSource con= (DataSource) ctx.lookup(JDNIName);//JNDI名称为mytest
URL = jdbc:weblogic:mssqlserver4:northwind@localhost:2040
Driver classname = weblogic.jdbc.mssqlserver4.Driver
Properties :user=sa
password = sa的密码
http://www.webshu.net/jiaocheng/programme/JSP/200804/6157.html
注意:9.0.0.0 Use a DataSource to get a database connection. 其实,还是推荐用datasource, 移植性强,一样效果-------------------------------------------------
爱问易 - 非官方技术支持互助平台
http://www.iaskengineer.com
-------------------------------------------------
几块钱就能解决的问题,何必困扰好几天?
-------------------------------------------------