This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes JDBC and the fly likes How to set up DataSource in plain Java application? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "How to set up DataSource in plain Java application?" Watch "How to set up DataSource in plain Java application?" New topic
Author

How to set up DataSource in plain Java application?

rick collette
Ranch Hand

Joined: Mar 22, 2002
Posts: 208
Hi,
I know how to set up datasource for servlet applications, we have to modify server.xml and web.xml in Tomcat to do the job.
I am wondering how I can set up datasource for plain java application such as getting datasource from a main method?
I try to do the same as for servlets, but it keep giving set up errors.
thanks,
Philip Shanks
Ranch Hand

Joined: Oct 15, 2002
Posts: 189
Here is a MySQL example:

Additionally, you can put your DataSource in a JNDI context for future easy access.


Philip Shanks, SCJP - Castro Valley, CA
My boss never outsources or has lay-offs, and He's always hiring. I work for Jesus! Prepare your resume!
Ron Newman
Ranch Hand

Joined: Jun 06, 2002
Posts: 1056
What is the benefit of doing this? Does it create a connection pool?


Ron Newman - SCJP 1.2 (100%, 7 August 2002)
David Gallardo
Author
Greenhorn

Joined: Jul 07, 2003
Posts: 18
There's not really any advantage. It's just a matter of consistency since you need to use DataSource if you're using JNDI. Sun's hinted that they may deprecate the traditional method of loading/registering the JDBC driver explicitly and leave DataSource as the only technique for connecting to a database.
@D


Co-author: "Eclipse in Action: A guide for the Java developer"<br />Author: "Java Oracle Database Development"
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: How to set up DataSource in plain Java application?
 
Similar Threads
Struts with MySql
struts with datasource problem
is my idea possible?(about datasource in a J2EE server)
datasource question
Hibernate and XA datasource