This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JDBC Connection with DataSource

 
Rob Grubb
Greenhorn
Posts: 13
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2905
1
Java Spring Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Balu Sadhasivam
Ranch Hand
Posts: 874
Android Java VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 13
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 874
Android Java VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Not sure about netbeans.. If its not in classpath . add it . whats the big deal ?
 
Rob Grubb
Greenhorn
Posts: 13
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yeah it is setup just cant import it for some strange reason.
 
Sagar Rohankar
Ranch Hand
Posts: 2905
1
Java Spring Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic