wood burning stoves
The moose likes JDBC and Relational Databases and the fly likes how to use javax.sql.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 use javax.sql.DataSource" Watch "how to use javax.sql.DataSource" New topic

how to use javax.sql.DataSource

Aijaz Soomro

Joined: Aug 31, 2002
Posts: 17
Any body can tell me that how to connect to the database without ejb datbase , i mean there is example, like
String dbString = "java:comp/env/jdbc/ZacDB";
InitialContext ic = new InitialContext();
DataSource ds = (DataSource) ic.lookup(dbString);
connection = ds.getConnection();

so, i want to connect my database , simple any.mdb,
so how should be connected, and what would be the dbString instead, of that above string
Amol Desai
Ranch Hand

Joined: Jan 29, 2003
Posts: 82
In the example jdbc/ZacDB is the name of the jdbc resource.
You have to specify a connection pool for the jdbc resource.
The connection pool will contain database parmaeters like user name ,password, and the databse(any.mdb in your case) you want to connect.
Hope this helps.
Which web/Application server are you using...may be then I can tell you how to create these resources on the server.
Get back if you have any issues
Aijaz Soomro

Joined: Aug 31, 2002
Posts: 17
Context ctx = new InitialContext();
DataSource ds = (DataSource)ctx.lookup("jdbc/dsname"); //give the name of ur db connectionConnection dbConnection = ds.getConnection();
according to above example i have used the test , which is the name of my microsoft access connection ,build be odbc, there is the exception (no initial context exception )that jdbc/test is not bound in the context, so, any body can tell me that how to bind it in the context. while that connection name is working fine in simple connectivity.
Jim Baker
Ranch Hand

Joined: Mar 10, 2002
Posts: 177
How to configur a connection pool w/o
using web/app server?
I agree. Here's the link: http://aspose.com/file-tools
subject: how to use javax.sql.DataSource
It's not a secret anymore!