Connecting to MYSQL using JSP on godaddy.com

Hi. I am trying to connect to the mysql database on godaddy.com using JSP's. godaddy.com 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:
<sql:setDataSource
var="example"
driver="com.mysql.jdbc.Driver"
url="jdbc:mysql://mysql server:port/databsename"
user=""
password=""
/>

 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 mysql55.secureserver.net:4365/name";
String user= "";
String pass= "";
try{
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;");

while(rs.next())
{
%>
<table> <tr>
<td><%= rs.getString("firstname") %></td>
<td><%= rs.getString("lastname") %></td>
</tr></table>
<%}
rs.close();
conn.close();
}catch(Exception e)
{
out.println(e.toString());
}
%>

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>
</sql:query>
milance445Asked:
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.

bloodredsunCommented:
Yes you can set up a datasource if the tomcat version is 5.0 as seen here http://tomcat.apache.org/tomcat-5.0-doc/jndi-datasource-examples-howto.html

this should allow jsps access to a datasource without requiring connection code
0
milance445Author Commented:
I saw this example, but I don't have access to the server.xml file on godaddy.com. 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.
0
Siva Prasanna KumarPrincipal Solutions ArchitectCommented:
http://forum.java.sun.com/thread.jspa?messageID=4159924

this link will surely help you as it has the solution too.
0
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 http://forum.java.sun.com/thread.jspa?messageID=4159924...this is where i got it from also.
0
milance445Author Commented:
I have solved my own problem though. I managed to setup the web.xml file to open the connection.
0
bloodredsunCommented:
Could you please post the solution so that others can benefit from seeing how you did it.
0
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"
    "http://java.sun.com/dtd/web-app_2_3.dtd">

<web-app>
    <context-param>
      <param-name>javax.servlet.jsp.jstl.fmt.locale</param-name>
      <param-value>en</param-value>
    </context-param>

    <context-param>
      <param-name>javax.servlet.jsp.jstl.fmt.localizationContext</param-name>
      <param-value>messages</param-value>
    </context-param>

    <context-param>
       <param-name>javax.servlet.jsp.jstl.sql.dataSource</param-name>
       
    <param-value>jdbc:mysql://mysql##.secureserver.net:port/databasename,com.mysql.jdbc.Driver,user,pass</param-value>
    </context-param>

    <taglib>
        <taglib-uri>http://jakarta.apache.org/taglibs/standard/scriptfree</taglib-uri>
        <taglib-location>/WEB-INF/scriptfree.tld</taglib-location>
    </taglib>

    <taglib>
        <taglib-uri>http://jakarta.apache.org/taglibs/standard/permittedTaglibs</taglib-uri>
        <taglib-location>/WEB-INF/permittedTaglibs.tld</taglib-location>
    </taglib>

</web-app>
0
GranModCommented:
PAQed with points refunded (250)

GranMod
Community Support Moderator
0

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
JSP

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.