File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JDBC and Relational Databases and the fly likes DataSource class 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 class" Watch "DataSource class" New topic

DataSource class

Nelson Nadal
Ranch Hand

Joined: Jun 06, 2002
Posts: 170
Hi fellows,

Just a question, is DataSource class used only for WAR applications? I mean will it not work unless I make my files inside WAR? I can't run my web database program using DataSources/JNDI... but I can run using DriverManager class only.... Thanks.

karthikeyan Chockalingam
Ranch Hand

Joined: Sep 06, 2003
Posts: 259
It may work. Please read Obtaining a Client Connection Using a DataSource in the link below
[ September 21, 2006: Message edited by: karthi keyan ]

Nelson Nadal
Ranch Hand

Joined: Jun 06, 2002
Posts: 170
Hi karthi,

Im using Jakarta 5x, but I will try to look to your referred link, maybe I missed something in xml configurations...

Many Thanks,
Masoud Kalali
Ranch Hand

Joined: Jul 08, 2004
Posts: 531

do you add the JDBC driver to tomcat shared library folder ?
you know that a datasource and a connection pool is managed by application server and application server create and take care of them for you.
so you need to add the JDBC driver to tomcat shared lib folder.

in case that this does not helps , can you past your datasource XML content (if you are using context.xml file) or tell give us more details about exception or error message that you get.


Masoud Kalali
Software Engineer - My Weblog - GlassFish Security
Nelson Nadal
Ranch Hand

Joined: Jun 06, 2002
Posts: 170
Hello Masoud Kalali,
I've got naming exception error... Im using MS ACCESS as the database... Ive downloaded the driver (type 4) for it, coz I assumed this is different.(is it different from JDBC ODBC we created in Control Panel?)

Below are the xml and codes for your reference. I've been stuck w/this for a week inspite of having book references...]



JNDIDataSource.xml I put this in C:\Program Files\Apache Software Foundation\Tomcat 5.5\conf\Catalina\localhost


I put the needed jar files under this directory
C:\Program Files\Apache Software Foundation\Tomcat 5.5\common\lib
Access_JDBC30.jar <---- Driver of MS Access

If I run from stand alone java like the one below... the database can access

String url = "jdbcdbc:student1";
String username = "anonymous";
String password = "guest";

// Load the driver to allow connection to the database
try {
Class.forName( "sun.jdbc.odbc.JdbcOdbcDriver" );
I agree. Here's the link:
subject: DataSource class
It's not a secret anymore!