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
Solved

weblogic - Setting data source in session

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
eclipse shortcuts 9 62
diffSum example 4 50
String array comparison 4 38
jboss 7.1 start up error 1 28
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 learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

809 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