Meaningless Drivel is fun!*
The moose likes JDBC 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
Bookmark "how to use javax.sql.DataSource" Watch "how to use javax.sql.DataSource" New topic
Author

how to use javax.sql.DataSource

Aijaz Soomro
Greenhorn

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
Hi,
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
Greenhorn

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?
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: how to use javax.sql.DataSource
 
Similar Threads
Connection Error WSAD to SQL Server
Looking up Datasource object from a stateless session bean in WSAD 5.0....
How use DataSource to get connection
connect to DB2 database
Problem occurs when using DataSource connection in WSAD