• 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

How to actually create a Datasource

 
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I've installed a MS SQL Server JDBC driver and got it working using a connection driver manager as in the following example.
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
Connection conn = DriverManager.getConnection
("jdbc:microsoft:sqlserver://server1:1433;User=test;Password=secret");

Now I want to use a Datasource.
To access a Datasource from my Java class I can do so by using the code:
Context ctx = new InitialContext();
DataSource ds = (DataSource)ctx.lookup("jdbc/EmployeeDB");
Connection con = ds.getConnection("matt", "wwf");

However what I want to know is how do you actually create the datasource that I will be referencing in my code as above.
 
Ranch Hand
Posts: 1879
MySQL Database Suse
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
have a look at Frank Carver's general implementation of the Connection Pool here
Jamie
 
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Usually, code that requires a DataSource is running from within a web/app server. These servers have tools (usually a GUI tool or a config file) that allow you to configure the properties of the DataSource, including JDBC driver class, URL, username, password and so on.
Each vendor most likely has a subclass of the DataSource class that implements the DataSource as they see fit. Basically, you just need to know that it is there and how to look it up. In most instances, you will not need to explicitly create it yourself.
reply
    Bookmark Topic Watch Topic
  • New Topic