Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

weblogic - Setting data source in session

Posted on 2006-07-03
3
Medium Priority
?
361 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 92

Accepted Solution

by:
objects earned 1400 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

The top UI technologies you need to be aware of

An important part of the job as a front-end developer is to stay up to date and in contact with new tools, trends and workflows. That’s why you cannot miss this upcoming webinar to explore the latest trends in UI technologies!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
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 if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:

688 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