errorpro
发贴: 2
积分: 0
|
于 2007-10-02 23:30
1。系统平台 WIN2003+WebLogic9.2+MS SQLServer2000(已经打上SP4补丁,使用的是SP3驱动)
2。修改C:\bea\weblogic92\server\bin\startWLS.cmd中的CLASSPATH set CLASSPATH=%JAVA_HOME%\lib\tools.jar;%WL_HOME%\server\lib\weblogic_sp.jar;%WL_HOME%\server\lib\weblogic.jar;%WL_HOME%\server\lib\msbase.jar;%WL_HOME%\server\lib\msutil.jar;%WL_HOME%\server\lib\mssqlserver.jar;
3。新建立的域中添加了msbase.jar,mssqlserver.jar,msutil.jar ,wlclient.jar包 C:\bea\user_projects\domains\base_domain\lib
4。在WebLogic9.2中不管使用WebLogic9.2自带的驱动还是选用MS的驱动测试连接都能完成。
5。测试代码如下: package com.until;
import java.sql.Connection; import java.util.Properties; import javax.naming.Context; import javax.naming.InitialContext; import javax.sql.DataSource;
public class ConnDatabasePool {
/** * @param args */ public static void main(String[] args) { Properties properties = null; DataSource ds=null; String user = null; String password = null; try { properties = new Properties(); properties.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory"); properties.put(Context.PROVIDER_URL, "t3://localhost:7001"); if (user != null) { properties.put(Context.SECURITY_PRINCIPAL, user); properties.put(Context.SECURITY_CREDENTIALS, password == null ? "" : password); }
Context ctx = new InitialContext(properties); ds = (javax.sql.DataSource) ctx.lookup("SQLServerJNDI");//SQLServerJNDI为WebLogic9.2 中配置的JNDI 名称 Connection con = ds.getConnection(); if(con!=null){ System.out.println("数据库连接成***!"); } }catch(Exception e){ System.out.println("数据库连接失败!"); System.out.println(e.getMessage()); } }
}
6。经编译下面测试程序后给出如下提示: 数据库连接失败! Unexpected Exception
希望大家能够帮助解决,谢谢!!!!!!!!!!!!!!!!!!
|