jbuilder9里编译出现下面错误,不解。

xyshine xyshine 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
java.lang.NullPointerException
at jdbcexample1.main(jdbcexample1.java:45)
Exception in thread "main" Init Error:javax.naming.NoInitialContextException: Cannot instantiate class: weblogic.jndi.WLInitialContextFactory [Root exception is java.lang.ClassNotFoundException: weblogic.jndi.WLInitialContextFactory]


代码如下:

import java.sql.*;
import javax.naming.*;
import javax.sql.*;
import java.util.Properties;
import java.util.*;
import javax.rmi.PortableRemoteObject;

public class jdbcexample1 {

public static void main(String[] args){
DataSource ds = null;
Context ctx = null;
Connection myConn = null;
Hashtable env = new Hashtable();
try{


env.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory");
env.put(Context.PROVIDER_URL, "t3://127.0.0.1:7001");
env.put("user", "system");
env.put("password", "12345678");

ctx = new InitialContext(env);

ds = (javax.sql.DataSource)ctx.lookup("myDataSource");
}
catch(Exception ex)
{
System.out.println("Init Error:" + ex);
}
Statement mystatement = null;
ResultSet myresultset = null;

try{
myConn = ds.getConnection();
mystatement = myConn.createStatement();

myresultset = mystatement.executeQuery("SELECT full_name from employee");

while(myresultset.next())
{
System.out.println("The employee full name is:" + myresultset.getString("full_name"));
}
myresultset.close();
}
catch(SQLException ex)
{
System.out.println("Error code = " + ex.getErrorCode());
System.out.println("Error message = " + ex.getMessage());
}
finally{
try{
if(mystatement != null)
{
mystatement.close();
}
if(myConn != null)
{
myConn.close();
}
}
catch(SQLException ex)
{
System.out.println("Error code = " + ex.getErrorCode());
System.out.println("Error message = " + ex.getMessage());
}

}
}
...全文
评论 4
收藏 已收藏
分享
返回顶部
xyshine
Java EE 67,535 成员 225,843 内容