Connecting to MYSQL using JSP on

Hi. I am trying to connect to the mysql database on using JSP's. only provided me with their server name and port number. I was wondering what is the best way to connect to it and keep the connection open always so that all JSP's that need to access the database have connection?
Is it possible to set up the connection settings in the web.xml file and have no code for that in the JSP's whatsoever?
I tried connecting to it with the following code and no luck:
url="jdbc:mysql://mysql server:port/databsename"

 I also tried with the sample code on their website FAQ but I don't think that this keeps the connection open always.
<%@ page contentType="text/html; charset=iso-8859-1" language="java"
import="java.sql.*" errorPage="" %>
String url = "jdbc:mysql://mysql";
String user= "";
String pass= "";
Class.forName ("com.mysql.jdbc.Driver").newInstance ();
Connection conn = DriverManager.getConnection(url, user, pass);
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("select * from a_reg;");

<table> <tr>
<td><%= rs.getString("firstname") %></td>
<td><%= rs.getString("lastname") %></td>
}catch(Exception e)

Does anyone know the best way to establish a connection so that all JSP's don't have any problems with commands like
<sql:query var="user">
select username from table where username = ?
<sql:param><c:out value='${param.username}' /></sql:param>
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Yes you can set up a datasource if the tomcat version is 5.0 as seen here

this should allow jsps access to a datasource without requiring connection code
milance445Author Commented:
I saw this example, but I don't have access to the server.xml file on Only web.xml. Is it possible to set up all the info like server name username,pass in the web.xml and not touch the server.xml file.
Siva Prasanna KumarPrincipal Solutions ArchitectCommented:

this link will surely help you as it has the solution too.
Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

milance445Author Commented:
I've already posted the code in my Q from the link is where i got it from also.
milance445Author Commented:
I have solved my own problem though. I managed to setup the web.xml file to open the connection.
Could you please post the solution so that others can benefit from seeing how you did it.
milance445Author Commented:
The main problem was the URL and taglib location.

<?xml version="1.0" encoding="ISO-8859-1"?>

<!DOCTYPE web-app
    PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"






PAQed with points refunded (250)

Community Support Moderator

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.