dkim18
asked on
weblogic - Setting data source in session
Hi,
I am trying to set data source in session, but getting null pointer exception. I checked data source and it was not null.
(ds: weblogic.jdbc.common.inter nal.RmiDat aSource@63 247b)
Here is the code:
Context initcntx = null;
Hashtable ht = new Hashtable();
ht.put(Context.INITIAL_CON TEXT_FACTO RY, "weblogic.jndi.WLInitialCo ntextFacto ry");
ht.put(Context.PROVIDER_UR L, "t3://localhost:7001");
try {
initcntx = new InitialContext(ht);
javax.sql.DataSource ds = (DataSource)initcntx.looku p(dsName);
session.setAttribute("ds", ds); ---------------> error!
...
...
...
++++++++++++++++=
java.lang.NullPointerExcep tion
at RegistrationController.ini t()V(Regis trationCon troller.ja va:60)
at javax.servlet.GenericServl et.init(Lj avax/servl et/Servlet Config;)V( Gen
ericServlet.java:258)
at weblogic.servlet.internal. ServletStu bImpl$Serv letInitAct ion.run()L jav
a/lang/Object;(ServletStub Impl.java: 1094)
at weblogic.security.acl.inte rnal.Authe nticatedSu bject.doAs (Lweblogic /se
curity/subject/AbstractSub ject;Ljava /security/ Privileged Action;)Lj ava/lang/O bjec
t;(AuthenticatedSubject.ja va:321)
at weblogic.security.service. SecurityMa nager.runA s(Lweblogi c/security /ac
l/internal/AuthenticatedSu bject;Lweb logic/secu rity/acl/i nternal/Au thenticate dSub
ject;Ljava/security/Privil egedAction ;)Ljava/la ng/Object; (SecurityM anager.jav a:12
1)
at weblogic.servlet.internal. ServletStu bImpl.crea teServlet( )Ljavax/se rvl
et/Servlet;(ServletStubImp l.java:970 )
at weblogic.servlet.internal. ServletStu bImpl.crea teInstance s()V(Servl etS
tubImpl.java:949)
I am trying to set data source in session, but getting null pointer exception. I checked data source and it was not null.
(ds: weblogic.jdbc.common.inter
Here is the code:
Context initcntx = null;
Hashtable ht = new Hashtable();
ht.put(Context.INITIAL_CON
ht.put(Context.PROVIDER_UR
try {
initcntx = new InitialContext(ht);
javax.sql.DataSource ds = (DataSource)initcntx.looku
session.setAttribute("ds",
...
...
...
++++++++++++++++=
java.lang.NullPointerExcep
at RegistrationController.ini
at javax.servlet.GenericServl
ericServlet.java:258)
at weblogic.servlet.internal.
a/lang/Object;(ServletStub
at weblogic.security.acl.inte
curity/subject/AbstractSub
t;(AuthenticatedSubject.ja
at weblogic.security.service.
l/internal/AuthenticatedSu
ject;Ljava/security/Privil
1)
at weblogic.servlet.internal.
et/Servlet;(ServletStubImp
at weblogic.servlet.internal.
tubImpl.java:949)
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
in case you have a request object in your scope you can set the object in the session as
request.getSession().setAt tribute("d s", ds);
Thanks/SSP
request.getSession().setAt
Thanks/SSP
Why do you need to put the datasource in the session? It is not necessary. You can call the DataSource at anywhere on your codes. It is not *expensive* and all the connections are handled effectively by WebLogic.
However, if you would like to put it in session, I will help you ;). Can you post your current codes? How do you initialise the session?
David