Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

Troubleshooting
Research
Professional Opinions
Ask a Question
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

troubleshooting Question

datasource issue

Avatar of Micheal_Male
Micheal_MaleFlag for Afghanistan asked on
JavaJava EE
17 Comments1 Solution401 ViewsLast Modified:
So i have an applicationContext.xml which has a bean dataSource defined in it.

<bean id="dataSource" class="org.apache.commons.....">
<propertyName="driverClassName">
<value>mysql....</value>
</property>
.
.
.
.
</bean>

<bean id="testDao" class="com.testDao">
<property name="dataSource" ref="dataSource"/>
</bean>

Now in my testDao i had the dataSource :-

private DataSource dataSource;

setters and getter for the datasource. Now in one of my method when i try to get connection from the dataSource it's always coming null. Any clue why is it doing that ?

Connection conn = null;
conn = getDataSource().getConnection();

I get a nullpointer exception in this statement, hence my queries don't get executed. Can anyone tell me how to get the connection instance from the dataSource ?
ASKER CERTIFIED SOLUTION
Avatar of mccarl
mccarlFlag of Australia imageIT Business Systems Analyst / Software Developer
Commented:
This problem has been solved!
Unlock 1 Answer and 17 Comments.
See Answers