aspose file tools*
The moose likes JDBC and the fly likes JDBC Connection with DataSource Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "JDBC Connection with DataSource" Watch "JDBC Connection with DataSource" New topic
Author

JDBC Connection with DataSource

Rob Grubb
Greenhorn

Joined: Aug 16, 2009
Posts: 13
Can anyone explain how to establish a connection to a database(derby in netbeans if possible) with DataSource instead of DriverManager? I know how to use DriverManager but DataSource is a little more complicated. I read that DataSource is what we should be using these days here.

http://java.sun.com/docs/books/tutorial/jdbc/basics/connecting.html

Rob G
Sagar Rohankar
Ranch Hand

Joined: Feb 19, 2008
Posts: 2902
    
    1

Welcome to JR.

The link you're referring has used the DataSource with JNDI. JNDI binds the db resource with the context and that context can be used to access any resource on the server, DB is one of its use.

As per JDBC spec, each DB vendor has to follow the contract of JDBC to implements its own JDBC driver. Here is the APIlink for Client data source implemented by Derby.

You can learn how set Initial context and how to get ds.

HTH


[LEARNING bLOG] | [Freelance Web Designer] | [and "Rohan" is part of my surname]
Balu Sadhasivam
Ranch Hand

Joined: Jan 01, 2009
Posts: 874


Rob,
If you have plans to use Glassfish server , Derby Data source is already configured and available to use.. how simple is tat
Rob Grubb
Greenhorn

Joined: Aug 16, 2009
Posts: 13
Hey thanks guys for the reply. I probly wont be using the Glassfish server anytime soon. Just need to use the Java derby database within netbeans for an assignment.

org.apache.derby.client.ClientDataSource dataSource = new org.apache.derby.client.ClientDataSource ();

is not known in a default install of Netbeans. I thought derby class paths were all set up in a defailt netbeans install. Any ideas?
Balu Sadhasivam
Ranch Hand

Joined: Jan 01, 2009
Posts: 874


Not sure about netbeans.. If its not in classpath . add it . whats the big deal ?
Rob Grubb
Greenhorn

Joined: Aug 16, 2009
Posts: 13
yeah it is setup just cant import it for some strange reason.
Sagar Rohankar
Ranch Hand

Joined: Feb 19, 2008
Posts: 2902
    
    1

Just add/import the derby database jar into a Netbeans projects "Libraries" and the NB take care of rest.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JDBC Connection with DataSource