aspose file tools*
The moose likes JSP and the fly likes Connecting JSP to MySQL Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Connecting JSP to MySQL" Watch "Connecting JSP to MySQL" New topic
Author

Connecting JSP to MySQL

Michael Carlson
Ranch Hand

Joined: Sep 11, 2005
Posts: 78
I have a JSP page called store.jsp, which simply takes input and writes to a database. I am having difficulty when I hit submit getting a connection to the database. In the web.xml file I have put
<context-param>
<param-name>
javax.servlet.jsp.jstl.sql.dataSource
</param-name>
<param-value>
jdbc:mysql:mydatabase,com.mysql.jdbc.Driver,username,password

</param-value>
</context-param>
Over all what I am trying to do is useing JSP pages: enter.jsp, store.jsp, search.jsp create a web application to access a mysql database.
Thanks
Michael Carlson
Ranch Hand

Joined: Sep 11, 2005
Posts: 78
Here is the error

javax.servlet.ServletException: Unable to get connection, DataSource invalid: "java.sql.SQLException: No suitable driver"
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:848)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:781)
org.apache.jsp.ch12.store_jsp._jspService(org.apache.jsp.ch12.store_jsp:129)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:322)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.apache.jasper.runtime.PageContextImpl.doForward(PageContextImpl.java:693)
org.apache.jasper.runtime.PageContextImpl.forward(PageContextImpl.java:660)
org.apache.jsp.ch12.validate_jsp._jspx_meth_c_when_4(org.apache.jsp.ch12.validate_jsp:1020)
org.apache.jsp.ch12.validate_jsp._jspx_meth_c_choose_2(org.apache.jsp.ch12.validate_jsp:984)
org.apache.jsp.ch12.validate_jsp._jspService(org.apache.jsp.ch12.validate_jsp:124)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:322)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
Naveen K Garg
Ranch Hand

Joined: Nov 28, 2005
Posts: 105
Hi Michael,

Did you check whether the JDBC driver for mySql is in your classpath. Did you copy it in tomcat/common/lib folder or in <your web application>/WEB-INF/lib folder.

Let us know.
Michael Carlson
Ranch Hand

Joined: Sep 11, 2005
Posts: 78
Yes, I tried what you have asked. I can access the database from a servlet using tomcat, but I can't get a connection from a JSP page in this web app.
Thanks
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61420
    
  67

Why are you trying to move such access from a servlet to the view? Most would argue that you're going in the wrong direction.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Michael Carlson
Ranch Hand

Joined: Sep 11, 2005
Posts: 78
Your right, but for this simple web app I just thought I would use pure JSP.
A learning experience.
I just figured out my web.xml context param was not configured correctly, works fine now.
Thanks once again!
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Connecting JSP to MySQL