Win a copy of Reactive Streams in Java: Concurrency with RxJava, Reactor, and Akka Streams this week in the Reactive Progamming forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Ganesh Patekar

Connecting JSP to MySQL

 
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)
 
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
 
Marshal
Posts: 67289
170
Mac Mac OS X IntelliJ IDE jQuery Java
  • 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!
 
What's brown and sticky? ... a stick. Or a tiny ad.
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!