• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How use DataSource to get connection

 
S. Palanigounder
Ranch Hand
Posts: 145
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
this is how u do it...

hope this helps..
 
Aijaz Soomro
Greenhorn
Posts: 17
  • 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 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic