Solved

weblogic - Setting data source in session

Posted on 2006-07-03
3
333 Views
Last Modified: 2013-11-24
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.internal.RmiDataSource@63247b)

Here is the code:

Context initcntx = null;
               Hashtable ht = new Hashtable();  
               ht.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory");
               ht.put(Context.PROVIDER_URL, "t3://localhost:7001");  
             
               try {
                     
                     initcntx = new InitialContext(ht);
           
                     javax.sql.DataSource ds = (DataSource)initcntx.lookup(dsName);
                        session.setAttribute("ds", ds); ---------------> error!
...
...
...
++++++++++++++++=
java.lang.NullPointerException
        at RegistrationController.init()V(RegistrationController.java:60)
        at javax.servlet.GenericServlet.init(Ljavax/servlet/ServletConfig;)V(Gen
ericServlet.java:258)
        at weblogic.servlet.internal.ServletStubImpl$ServletInitAction.run()Ljav
a/lang/Object;(ServletStubImpl.java:1094)
        at weblogic.security.acl.internal.AuthenticatedSubject.doAs(Lweblogic/se
curity/subject/AbstractSubject;Ljava/security/PrivilegedAction;)Ljava/lang/Objec
t;(AuthenticatedSubject.java:321)
        at weblogic.security.service.SecurityManager.runAs(Lweblogic/security/ac
l/internal/AuthenticatedSubject;Lweblogic/security/acl/internal/AuthenticatedSub
ject;Ljava/security/PrivilegedAction;)Ljava/lang/Object;(SecurityManager.java:12
1)
        at weblogic.servlet.internal.ServletStubImpl.createServlet()Ljavax/servl
et/Servlet;(ServletStubImpl.java:970)
        at weblogic.servlet.internal.ServletStubImpl.createInstances()V(ServletS
tubImpl.java:949)
0
Comment
Question by:dkim18
3 Comments
 
LVL 92

Accepted Solution

by:
objects earned 350 total points
ID: 17033941
there is no session available at servlet initialisation.
Session is only available for a request
0
 
LVL 16

Expert Comment

by:suprapto45
ID: 17034446
Hi,

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
0
 
LVL 3

Expert Comment

by:ss_p
ID: 17051404
in case you have a request object in your scope you can set the object in the session as

request.getSession().setAttribute("ds", ds);

Thanks/SSP
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

I had a project requirement for a displaying a user workbench .This workbench would consist multiple data grids .In each grid the user will be able to see a large number of data. These data grids should allow the user to 1. Sort 2. Export the …
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now