File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to use javax.sql.DataSource

 
Aijaz Soomro
Greenhorn
Posts: 17
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 82
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 17
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 177
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How to configur a connection pool w/o
using web/app server?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic