这是代码:
import javax.sql.*;
import java.sql.*;
import javax.naming.*;
import java.util.Properties;
import javax.rmi.PortableRemoteObject;public class WLTestPool{ public static void main(String args[]){
String dsName = "MyDataSource";
DataSource ds = null;
Context ctx = null;
Connection myConn = null;
try{
ctx = getInitialContext();
//查找JNDI名字为dsName的数据源
//System.out.println("get Context successfully");
ds = (DataSource)ctx.lookup(dsName);
}catch(Exception E){
System.out.println("Init DataSource Error:"+E);
}
try{
if (ds!=null){
myConn = ds.getConnection();
myConn.close();
}
}catch(Exception E){
System.out.println("Init Connection Error:"+E);
} }
private static Context getInitialContext() throws Exception{
String url = "t3://localhost:7001";
String user = "weblogic";
String password = "dltstudy";
Properties properties = null;
try{
properties = new Properties();
properties.put(Context.INITIAL_CONTEXT_FACTORY,"weblogic.jndi.WLInitialContextFactory");
properties.put(Context.PROVIDER_URL,url);
properties.put(Context.SECURITY_PRINCIPAL,user);
properties.put(Context.SECURITY_CREDENTIALS,password);
//System.out.println("new proerties");
return new InitialContext(properties);
}catch(Exception e){
throw e;
}
}
}
import javax.sql.*;
import java.sql.*;
import javax.naming.*;
import java.util.Properties;
import javax.rmi.PortableRemoteObject;public class WLTestPool{ public static void main(String args[]){
String dsName = "MyDataSource";
DataSource ds = null;
Context ctx = null;
Connection myConn = null;
try{
ctx = getInitialContext();
//查找JNDI名字为dsName的数据源
//System.out.println("get Context successfully");
ds = (DataSource)ctx.lookup(dsName);
}catch(Exception E){
System.out.println("Init DataSource Error:"+E);
}
try{
if (ds!=null){
myConn = ds.getConnection();
myConn.close();
}
}catch(Exception E){
System.out.println("Init Connection Error:"+E);
} }
private static Context getInitialContext() throws Exception{
String url = "t3://localhost:7001";
String user = "weblogic";
String password = "dltstudy";
Properties properties = null;
try{
properties = new Properties();
properties.put(Context.INITIAL_CONTEXT_FACTORY,"weblogic.jndi.WLInitialContextFactory");
properties.put(Context.PROVIDER_URL,url);
properties.put(Context.SECURITY_PRINCIPAL,user);
properties.put(Context.SECURITY_CREDENTIALS,password);
//System.out.println("new proerties");
return new InitialContext(properties);
}catch(Exception e){
throw e;
}
}
}
解决方案 »
- 怎么在jsp里调用自己实现的类
- Premature end of file. Nested exception: Premature end of file.这个错是什么原因?
- div层跟着鼠标走,到了下面不下去了
- 一个简单的实现。。。没思路
- 使用hibernate3调用mysql5.0的存储过程出现问题
- servlet 相关问题
- 请问在java中怎样才能得到windows系统的环境变量的值
- 对于:ctx.lookup("java:comp/env/ejb/XXXXHome")这一句,其中java:comp/env/ejb的意思指的是什么???
- 用Struts2的Action返回图片流,总提示不能将ByteArrayInputStream转换为String
- 实体类之间的转换
- 各位大大帮帮忙!!编写一个jar包,如何进行测试?
- 初学,请指点!关于weblogic 的配置
是这句话发生了错误,取不连接。但在Weblogic中是有的,而且数据库中也能够看到连接数目。
高手们,问题出在哪里?
不够可以加分。
<2004-9-13 下午02时41分05秒 CST> <Warning> <JDBC> <BEA-001074> <A JDBC pool conn
ection leak was detected. A connection leak occurs when a connection obtained fr
om the pool was not closed explicitly by calling close() and then was disposed b
y the garbage collector and returned to the connection pool. The following stack
trace at create shows where the leaked connection was created. [Null exception
passed, creating stack trace for offending caller]
at weblogic.utils.StackTraceUtils.throwable2StackTrace(StackTraceUtils.j
ava:28)
at weblogic.jdbc.wrapper.PoolConnection.finalizeInternal(PoolConnection.
java:84)
at weblogic.jdbc.wrapper.PoolConnection_com_borland_datastore_jdbc_RConn
ection.finalize(Unknown Source)
at java.lang.ref.Finalizer.invokeFinalizeMethod(Native Method)
at java.lang.ref.Finalizer.runFinalizer(Finalizer.java:83)
at java.lang.ref.Finalizer.access$100(Finalizer.java:14)
at java.lang.ref.Finalizer$FinalizerThread.run(Finalizer.java:160)
>
改为
ctx = new InitialContext();
试试
ctx = new InitialContext();
改为这个也不行。如下错误:
Init DataSource Error:javax.naming.NoInitialContextException: Need to specify cl
ass name in environment or system property, or as an applet parameter, or in an
application resource file: java.naming.factory.initial
This situation occurs because on server restart, WebLogic Server calls XA.recover() to recover any pending transactions. With the 9.2.0.3 or earlier version of the Oracle Thin driver, the Oracle DBMS opens a local transaction to complete the transaction recovery work, but the local transaction is never closed. When the connection used to recover transactions is returned to the connection pool and is then reused by an application, the local transaction is still present. With the first operation on the connection, an XAER_PROTO error is thrown. (If TestConnsOnReserve is set to true, the connection test is the first operation on the connection.) WebLogic Server then attempts to unregister the connection with the resource and waits a fixed amount of time for all transaction work on the resource to complete. This may appear as a hang.