DataSource problem

D

datanet

Hi,

I would like to use javax.sql.DataSource to connect to the database from a
simple application.
I have the next program fragment:

Context initctx = new InitialContext();
javax.sql.DataSource ds = (javax.sql.DataSource)initctx.lookup(
"java:comp/env/jdbc/MyDatabase");

java.sql.Connection cx = ds.getConnection(user,password);


I do not know how what "java:comp/env/jdbc/MyDatabase" means and how to set
the database url, the jdbc driver and so on.

I have read many documents but I cannot find the solution. Can anybody help
me?

Okip
 
A

Andy Fish

javax.sql.datasource is just an interface implemented by JDBC drivers. you
cannot connect to the database without finding or buying a JDBC driver.

when you have chosen and procured your driver, the documentation for it will
tell you what parameters to use for the URL and driver class.

Andy
 
D

datanet

All right.
I have JDBC driver let us call it jdbc.jar. It is located in directory
/usr/share/db. Database URL: jdbc:mydatabase:mydb

So, how can I use DataSource?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,431
Messages
2,571,679
Members
48,796
Latest member
Greg L.

Latest Threads

Top