Solved

weblogic - Setting data source in session

Posted on 2006-07-03
3
336 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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
firstswap challenge 20 67
advertisement module in core php 4 144
Java Jpanels and Jframe 8 28
Why my table column Id is not passed to java object? 4 24
INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
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:
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

911 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

14 Experts available now in Live!

Get 1:1 Help Now