aspose file tools*
The moose likes JDBC and the fly likes How use DataSource to get connection Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "How use DataSource to get connection" Watch "How use DataSource to get connection" New topic
Author

How use DataSource to get connection

S. Palanigounder
Ranch Hand

Joined: Apr 03, 2003
Posts: 145
How use DataSource to get Connection
w/o using web and app server? How to
set url, userID, password in the
DataSource?
Lilac Ezer
Greenhorn

Joined: Apr 08, 2003
Posts: 8
I'm not sure why you need to use a DataSource to get the Connection. Here is how you can create a connection manually (SQL Server example):
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
Connection con = DriverManager.getConnection("jdbc:microsoft:sqlserver://" + server +
":" + port + ";DatabaseName=Master;", username, password);
Aijaz Soomro
Greenhorn

Joined: Aug 31, 2002
Posts: 17
mr green hold could not understand the , problem, actually DataSource is the, feature for builtin connection booling, so, i am also still , looking that , how to connect throug DataSource to the normal database
Rajeshwari Natarajan
Ranch Hand

Joined: Mar 05, 2003
Posts: 67
this is how u do it...

hope this helps..


regards<br />Rajeshwari. N
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 connectionConnectiondbConnection = 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 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.
 
 
subject: How use DataSource to get connection