Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Connecting JSP to MySQL

 
Michael Carlson
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 78
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 105
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 78
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64715
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Michael Carlson
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic