关于weblogic中数据源连接的问题!

playerboy1983 2004-10-21 04:04:55
关于数据库的连接我写了如下的一段程序:
public class DataBaseConnection {

public static Connection getConnection() {
DataSource ds = null;
Context ctx = null;
Connection myConn = null;

try {
ctx = getInitialContext();
ds = (javax.sql.DataSource) ctx.lookup("MYJDBCDataSource_1");

}
catch (Exception E) {
System.out.println("LHN Error:" + E);
}

try {
myConn = ds.getConnection();

}
catch (Exception e) {
e.printStackTrace();
return null;
}
return myConn;

}

private static Context getInitialContext() throws Exception {
String url = "t3://192.168.20.32:7001";
String user = "weblogic";
String password = "11111111";
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;
}
}
}

但是每次调用的时候weblogic 总是会报出:
Error 500--Internal Server Error
java.lang.NullPointerException
at text_1.AddData.Add(AddData.java:26)
at jsp_servlet.__jsp1._jspService(__jsp1.java:153)
at weblogic.servlet.jsp.JspBase.service(JspBase.java:33)
at weblogic.servlet.internal.ServletStubImpl$ServletInvocationAction.run(ServletStubImpl.java:971)
at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:402)
at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:305)
at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:6350)
at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:317)
at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:118)
at weblogic.servlet.internal.WebAppServletContext.invokeServlet(WebAppServletContext.java:3635)
at weblogic.servlet.internal.ServletRequestImpl.execute(ServletRequestImpl.java:2585)
at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:197)
at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:170)



研究多时未能出结果,请各位帮忙!

谢谢!

...全文
71 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
playerboy1983 2004-10-22
  • 打赏
  • 举报
回复
AddData.java的原码如下
第26行是一段sql查询输入语句
是不是我的数据库连接有问题?

package text_1;

public class AddData {

private Connection con;


public AddData() {

this.con=DataBaseConnection.getConnection();

}
public void Add(Data data)throws Exception{
PreparedStatement pstmt = con.prepareStatement("insert into TEMP values(?)");//这个就
pstmt.setString(1,data.getTitle()); //是第二十六行
pstmt.execute();
con.close();

}
}
trumplet 2004-10-22
  • 打赏
  • 举报
回复
问题出在AddData.java第26行。Add方法,从字面意思上看,系统配置应该没有问题。是不是有变量没初始化,

1,220

社区成员

发帖
与我相关
我的任务
社区描述
企业软件 中间件技术
社区管理员
  • 中间件
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧