| 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: 56204
|
|
|
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.
|
[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About 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!
|
 |
 |
|
|
subject: Connecting JSP to MySQL
|
|
|