Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
The moose likes JDBC and Relational Databases and the fly likes datasource for mysql Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "datasource for mysql" Watch "datasource for mysql" New topic

datasource for mysql

divya kundapur
Ranch Hand

Joined: Aug 21, 2007
Posts: 110

I m using struts1.2.9, tomcat 6 and mysql. I m trying to establish connection pooling and have done the following

in META-INF/context.xml

<Context path="" reloadable="false">
<Resource driverClassName="com.mysql.jdbc.Driver" maxActive="40" maxIdle="5" maxWait="5000" minEvictableIdleTimeMillis="30000" name="jdbc/mydB" password="root123" testOnBorrow="true" testWhileIdle="true" type="javax.sql.DataSource" url="jdbc:mysql://localhost:3306/test?autoReconnect=true&zeroDateTimeBehavior=convertToNull" username="root"/>

wrote a java class

when i try to open db connection i m getting null pointer exception.. What else needs to be configured to get this working. any ideas are welcome.

Thank you

SCJP - 5.0
amit punekar
Ranch Hand

Joined: May 14, 2004
Posts: 544
I am not sure where in you code you are getting the NPE.
But the code below looks wrong, probably you can correct it and check .

Line 1 seems wrong and will fetch the resource that is DataSource and not the Context.
Instead you should just have something like

Where datasource string can be JNDI Name of the datasource. In your case "java:comp/env/jdbc/mydB".

I agree. Here's the link:
subject: datasource for mysql
It's not a secret anymore!