aspose file tools*
The moose likes JDBC and the fly likes Setting up Datasource object Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Setting up Datasource object" Watch "Setting up Datasource object" New topic
Author

Setting up Datasource object

shaf maff
Ranch Hand

Joined: Sep 07, 2008
Posts: 180
Hi Guys

I was going through some tutorials, I want to learn how to make a datasource object. Below is some code used in the tutorial:



I am alittle confused on how to configure it to work with mine current setup. I have the mysql-connector-java-5.1.6 driver in my lib folder and the link to the mysql db is mysql://localhost/faultsystem?user=myuser&password=mypassword. Can someone tell me what I need to edit in order to get it to work ?


Thanks
Bauke Scholtz
Ranch Hand

Joined: Oct 08, 2006
Posts: 2458
It depends on the environment you're running on. That environment should be configured to provide you the datasource through JNDI.

Before giving the detailed answer, we need to know which environment you're running on.
Bauke Scholtz
Ranch Hand

Joined: Oct 08, 2006
Posts: 2458
By the way, the given code doesn't compile and is wrong at several places. Where did you get it from?
shaf maff
Ranch Hand

Joined: Sep 07, 2008
Posts: 180
Im not entirely sure what you mean by enviroment. Im using tomcat 5 if thats of any help.

I got it from here: http://java.sun.com/docs/books/tutorial/jdbc/basics/connecting.html
Bauke Scholtz
Ranch Hand

Joined: Oct 08, 2006
Posts: 2458
shaf maff wrote:Im not entirely sure what you mean by enviroment. Im using tomcat 5 if thats of any help.

Then read this how to create a datasource in Tomcat so that you can use it in your application: http://tomcat.apache.org/tomcat-5.5-doc/jndi-datasource-examples-howto.html It contains lot of information and examples.
I see. I've reported it by the feedback link. Hope they fix it soon.
shaf maff
Ranch Hand

Joined: Sep 07, 2008
Posts: 180
Thanks - Sorry, I am using tomcat6. I found the tutorial for it: http://tomcat.apache.org/tomcat-6.0-doc/jndi-datasource-examples-howto.html

The problem is it shows how to implement it in a JSP but not a servlet.
Bauke Scholtz
Ranch Hand

Joined: Oct 08, 2006
Posts: 2458
In a servlet (you should rather do it in the DAO class) just get it from the JNDI context as follows:

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Setting up Datasource object