请问关于weblogic.jndi.WLInitialContextFactory的问题
我建了一个工程jdbc_direct
建立了一个应用程序jdbc_direct
然后建立一个类:jdbc_direct.java
其代码:
package jdbcexample;
import java.sql.*;
import javax.naming.*;
import javax.sql.*;
import java.util.*;
import javax.rmi.*;
public class Example1 {
public static void main(String[] args) {
DataSource ds = null;
Context ctx = null;
Connection myConn = null;
try
{
/* 获得WebLogic ServerJNDI初始上下文信息
*/
ctx = getInitialContext();
/* 建立数据源对象
*/
ds = (javax.sql.DataSource)
ctx.lookup("cyoracleDataSource");
}
catch (Exception E)
{
System.out.println("Init Error: " + E);
}
Statement myStatement=null;
ResultSet myResultSet=null;
try
{
//建立连接
myConn = ds.getConnection();
// 建立语句对象
myStatement = myConn.createStatement();
//建立结果集对象
myResultSet = myStatement.executeQuery(
"SELECT * from SCOTT.EMP"
);
//遍历结果集对象,访问每一条记录,输出full_name字段
while(myResultSet.next())
{
System.out.println("the employee full name is " + myResultSet.getString("ENAME"));
}
//关闭结果集
myResultSet.close();
}
catch (SQLException e)
{
System.out.println("Error code = " + e.getErrorCode());
System.out.println("Error message = " + e.getMessage());
}
finally
{
try
{
// close the Statement object using the close() method
if (myStatement != null)
{
myStatement.close();
}
// close the Connection object using the close() method
if (myConn != null)
{
myConn.close();
}
}
catch (SQLException e)
{
System.out.println("Error code = " + e.getErrorCode());
System.out.println("Error message = " + e.getMessage());
}
}
}
private static Context getInitialContext() throws Exception {
String url = "t3://localhost:7001";
String user = "cuiyi";
String password = "12345678";
Properties properties = null;
try {
properties = new Properties();
properties.put(Context.INITIAL_CONTEXT_FACTORY,
"weblogic.jndi.WLInitialContextFactory");
properties.put(Context.PROVIDER_URL, url);
if (user != null) {
properties.put(Context.SECURITY_PRINCIPAL, user);
properties.put(Context.SECURITY_CREDENTIALS, password == null ? "" : password);
}
return new InitialContext(properties);
}
catch(Exception e) {
throw e;
}
}
}
我用的是oracle9i数据库 jb+weblogic来开发 数据源JDBC连接池配制没问题
可是为什么总是在编译的时间提示:
E:\JBuilder9\jdk1.4\bin\javaw -classpath "C:\J2EE应用开发(JB+weblogic)\weblogic\源代码\第4章\jdbcexample\classes;E:\JBuilder9\jdk1.4\demo\jfc\Java2D\Java2Demo.jar;E:\JBuilder9\jdk1.4\demo\plugin\jfc\Java2D\Java2Demo.jar;E:\JBuilder9\jdk1.4\jre\lib\charsets.jar;E:\JBuilder9\jdk1.4\jre\lib\jaws.jar;E:\JBuilder9\jdk1.4\jre\lib\jce.jar;E:\JBuilder9\jdk1.4\jre\lib\jsse.jar;E:\JBuilder9\jdk1.4\jre\lib\rt.jar;E:\JBuilder9\jdk1.4\jre\lib\sunrsasign.jar;E:\JBuilder9\jdk1.4\jre\lib\ext\dnsns.jar;E:\JBuilder9\jdk1.4\jre\lib\ext\ldapsec.jar;E:\JBuilder9\jdk1.4\jre\lib\ext\localedata.jar;E:\JBuilder9\jdk1.4\jre\lib\ext\sunjce_provider.jar;E:\JBuilder9\jdk1.4\jre\lib\im\indicim.jar;E:\JBuilder9\jdk1.4\lib\dt.jar;E:\JBuilder9\jdk1.4\lib\htmlconverter.jar;E:\JBuilder9\jdk1.4\lib\tools.jar" jdbcexample.Example1
java.lang.NullPointerException
at jdbcexample.Example1.main(Example1.java:30)
Exception in thread "main" Init Error: javax.naming.NoInitialContextException: Cannot instantiate class: weblogic.jndi.WLInitialContextFactory [Root exception is java.lang.ClassNotFoundException: weblogic.jndi.WLInitialContextFactory]
找不到weblogic.jndi.WLInitialContextFactory呢?
我把weblogic81下的server下的lib下的weblogic.jar 拷贝到了c:\jdk\lib下并加载到环境变量里了,请问还需要做什么来补救?