|
Java学習Zhe论坛
关于数据库的连接我写了Ru下的一段程序:
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)
研究多时未能出结果,请各位帮忙!
謝谢!
欢迎来到Java学习者论壇,转載请注明地址:http://www.javaxxz.com. |
|