properties.put(Context.INITIAL_CONTEXT_FACTORY,"weblogic_jndi_WLInitialContextFactory");你看看这样行不
解决方案 »
- hibernate中无主键表映射的问题
- 大神帮忙看下是什么原因,表单提交不了
- 咨询下,这些字段数据库是怎么建的?
- 大家对vuser=(Vector)ois.readObject();是如何理解的
- struts 问题
- spring 3.4的jar包在官网哪里下载
- 怎么才能同时提供TCP连接服务器和web服务?
- servlet如何在相对路径下创建目录及删除相对路径下的文件??
- 关于weblogic中SessionBean能存活多长时间的问题??
- 请问谁能把HelloWorld的EJB的例子给我一份
- 使用XPath,如何去取得指定的节点的下一个兄弟节点?
- www.crackj2ee.com推出J2EE入门教程,欢迎访问!请多提意见!
不能初始化类...
weblogic.jar在你的classpath了吗?
import java.sql.*;
import javax.naming.*;
import javax.sql.DataSource;
import java.util.*;/**
* <p>Description:数据访问工厂</p>
* Date:2004.6.21
*
*/
public abstract class DBDAOFactory { public static Connection conn = null;
public abstract DBDAO createDAO(); //创建连接
public static DBDAO createDBDAOFactory(String tablename) {
return new OracleDBDAOFactory(tablename).createDAO();
} //添加一个静态方法,该方法的作用是获得WebLogic Server的初始上下文环境以进行JNDI查询
private static Context getInitialContext() throws Exception {
//t3代表控制台通信协议,对应WebLogic Server的地址、端口号
String url = "t3://localhost:7001";
String user = "weblogic"; //对应WebLogic Server的系统用户名
String password = "weblogic"; //对应WebLogic Server的口令
Properties prop = null; //声明属性包对象
try {
prop = new Properties();
prop.put(Context.INITIAL_CONTEXT_FACTORY,
"weblogic.jndi.WLInitialContextFactory");
prop.put(Context.PROVIDER_URL, url); //确定提供命名服务的Weblogic服务器的URL
if (user != null) {
prop.put(Context.SECURITY_PRINCIPAL, user); //为认证的目的确定用户(即在Weblogic服务器安全领域定义的用户)的身份。
prop.put(Context.SECURITY_CREDENTIALS, password);
}
return new InitialContext(prop);
}
catch (Exception e) {
throw e;
}
} //一个静态方法,返回一个数据库的连接,这样达到了对数据库连接统一控制的目的
public static Connection getConnection() {
Context ctx = null;
DataSource datasource = null;
try {
//获得WebLogic Server JNDI初始上下文信息
ctx = getInitialContext();
//建立数据源对象,查找JNDI名字为MyJDBCDataSource的数据源
datasource = (javax.sql.DataSource) ctx.lookup("MyJDBCDataSource");
try {
conn = datasource.getConnection(); //通过数据源对象建立数据连接
}
catch (SQLException se) {
se.printStackTrace();
}
}
catch (Exception ex) {
} return conn;
} //关闭连接
public static void cleanup(ResultSet pResultSet,
Statement pStmt,
Connection pConn) throws SQLException { try {
if (pResultSet != null) {
pResultSet.close();
pResultSet = null;
}
}
catch (SQLException e) {
throw e;
}
finally {
try {
if (pStmt != null) {
pStmt.close();
pStmt = null;
}
}
catch (SQLException e) {
throw e;
}
finally {
try {
if (pConn != null) {
pConn.close();
pConn = null;
}
}
catch (SQLException e) {
throw e;
}
}
}
}}
javax.naming.CommunicationException [Root exception is java.net.ConnectException: t3://localhost:7001: Destination unreachable; nested exception is:
java.net.ConnectException: Connection refused: connect; No available router to destination]
这是什么异常????
Unable to resolve 'test' Resolved
我的数据源的JNDIName绝对是test,并且发布在了目标域。请问这是为什么?是不是该碰上的异常我都碰上了?倒霉!!!