Sorry, I am unable to make a short descriptive title.
Well, i have made datasource in tomcat server.xml file. But now i am confuse how to get the connection ...
is it the correct syntax
I am unable to get connnection using this.
Now second question, if i got the connection what will be method that i release it. i.e suppose if a class need a connection for DB, i'll call the above CORRECTED code, the class will do the manipulation and then what? should i have to explicitly release the connection or not?
The difference between <b>failure</b> and <b>success</b> is often being <b>right</b> and being <b>exactly right</b>.
Please check that whether you can see your defined datasource in tomcat admin console or not. It is better to use admin console for configuring server , not to add them manually. your code looks correct and it should return a connection from a datasource with jdbc/DB name in tomcat JNDI .
to make sure that you have configured the correct datasource check it in tomcat admin console.
One more question. How is the working of close method in this case? i.e will the connection is returned back to the tomcat container?
calling the Datasource.getConnection() will return a connection object from the Container of the tomcat? does this mean on server startup, the tomcat creates a pool of connections and we reuse these connection throughout our code?