Win a copy of JDBC Workbook this week in the JDBC and Relational Databases forum
or A Day in Code in the A Day in Code forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

datasource for mysql

 
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

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"/>
<WatchedResource>WEB-INF/web.xml</WatchedResource>
</Context>

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
 
Ranch Hand
Posts: 544
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
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".


 
Their achilles heel is the noogie! Give them noogies tiny ad!
Devious Experiments for a Truly Passive Greenhouse!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic