• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

JDBC Connection with DataSource

 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 2908
1
Spring Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 874
Android VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
yeah it is setup just cant import it for some strange reason.
 
Sagar Rohankar
Ranch Hand
Posts: 2908
1
Spring Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Just add/import the derby database jar into a Netbeans projects "Libraries" and the NB take care of rest.
reply
    Bookmark Topic Watch Topic
  • New Topic