File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JDBC and Relational Databases and the fly likes How to actually create a Datasource Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "How to actually create a Datasource" Watch "How to actually create a Datasource" New topic

How to actually create a Datasource

Fergus Red
Ranch Hand

Joined: Apr 25, 2002
Posts: 42
I've installed a MS SQL Server JDBC driver and got it working using a connection driver manager as in the following example.
Connection conn = DriverManager.getConnection

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.
Jamie Robertson
Ranch Hand

Joined: Jul 09, 2001
Posts: 1879

have a look at Frank Carver's general implementation of the Connection Pool here
Ken Robinson
Ranch Hand

Joined: Jul 25, 2002
Posts: 52
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.
I agree. Here's the link:
subject: How to actually create a Datasource
jQuery in Action, 3rd edition