0

I just follow the practice of Creating a Simple Web Application Using a MySQL Database on Netbeans page and encountered an error.

I couldn't run my initial steps with glassfish so install tomcat and it worked fine for simpler version. After adding the MySQL DB. I have defined a JDBC Resource utilizing Netbeans glassfish functionality as document explained. However I refer these resource under my web.xml and glassfish-resources.xml, I am encountering the error.

I think that I should define the jdbc source to tomcat in a different way than whatever tutorial showed to notice it but I am a newbie and doesn't have too much background.

I will appreciate if you could give me some idea or a reference document which is easy to understand for a newbie.

Here is the log file.

TTP Status 500 - An exception occurred processing JSP page /index.jsp at line 9 type Exception report message An exception occurred processing JSP page /index.jsp at line 9 description The server encountered an internal error that prevented it from fulfilling this request.

exception org.apache.jasper.JasperException: An exception occurred processing JSP page /index.jsp at line 9
6: Author : XXX
7: --%>
8:
9:
10: SELECT subject_id, name FROM subject
11:
12:

Stacktrace:

org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:568)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:455)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:396)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:340)
javax.servlet.http.HttpServlet.service(HttpServlet.java:725)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:393)

root cause

javax.servlet.ServletException: javax.servlet.jsp.JspException: Unable to get connection, DataSource invalid: "java.sql.SQLException: No suitable driver found for jdbc/IFPNEW"
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:906)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:835)
org.apache.jsp.index_jsp._jspService(index_jsp.java:153)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:725)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:396)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:340)
javax.servlet.http.HttpServlet.service(HttpServlet.java:725)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:393)

root cause

javax.servlet.jsp.JspException: Unable to get connection, DataSource invalid: "java.sql.SQLException: No suitable driver found for jdbc/IFPNEW"
org.apache.taglibs.standard.tag.common.sql.QueryTagSupport.getConnection(QueryTagSupport.java:318)
org.apache.taglibs.standard.tag.common.sql.QueryTagSupport.doStartTag(QueryTagSupport.java:201)
org.apache.jsp.index_jsp._jspx_meth_sql_005fquery_005f0(index_jsp.java:175)
org.apache.jsp.index_jsp._jspService(index_jsp.java:89)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:725)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:396)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:340)
javax.servlet.http.HttpServlet.service(HttpServlet.java:725)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:393)

context.xml

       <?xml version="1.0" encoding="UTF-8"?>
<Context antiJARLocking="true" path="/tompool">
  <!-- maxActive: Maximum number of database connections in pool. Make sure you
         configure your mysqld max_connections large enough to handle
         all of your db connections. Set to -1 for no limit.
         -->
  <!-- maxIdle: Maximum number of idle database connections to retain in pool.
         Set to -1 for no limit.  See also the DBCP documentation on this
         and the minEvictableIdleTimeMillis configuration parameter.
         -->
  <!-- maxWait: Maximum time to wait for a database connection to become available
         in ms, in this example 10 seconds. An Exception is thrown if
         this timeout is exceeded.  Set to -1 to wait indefinitely.
         -->
  <!-- username and password: MySQL username and password for database connections  -->
  <!-- driverClassName: Class name for the old mm.mysql JDBC driver is
         org.gjt.mm.mysql.Driver - we recommend using Connector/J though.
         Class name for the official MySQL Connector/J driver is com.mysql.jdbc.Driver.
         -->
  <!-- url: The JDBC connection url for connecting to your MySQL database.
         -->
  <Resource auth="Container" driverClassName="com.mysql.jdbc.Driver" maxActive="100" maxIdle="30" maxWait="10000" name="jdbc/IFPNEW" password="...." type="javax.sql.ConnectionPoolDataSource" url="jdbc:mysql://localhost:3306/connpool" username="....."/>
</Context>
Willy
  • 45
  • 1
  • 8
  • Did you include `mysql-connector-java-[version]-bin` in your classpath? It should be placed in the `tomcat/lib folder`. – Richard Osseweyer Oct 26 '15 at 07:37
  • It is under Apache Tomcat 8.0.15\bin folder but I downloaded it after reading posts from internet. version is 5.1.6.jar but mysql version is 5.7 and tomcat version is 8.0.15 netbeans version is 8 Is it possible that version of connector is incorrect – Willy Oct 26 '15 at 10:17
  • It should be put in the `lib` folder, not `bin`. You can download the latest version here http://dev.mysql.com/downloads/connector/j/ After copying the jar into the lib folder restart Tomcat. – Richard Osseweyer Oct 26 '15 at 10:29
  • It was also in lib folder but I replaced it with the latest connector file. Error is same. I do believe that it is related to my jdbc Resource because I have created it from netbeans and maybe Tomcat doesn't consider it. – Willy Oct 26 '15 at 12:24
  • Could you perhaps post context.xml? How did you define the `jdbc/IFPNEW` resource? – Richard Osseweyer Oct 26 '15 at 14:26
  • When I raised the post it was different but then I changed it based on a documentation which explains to define connection pooling for Tomcat with net beans. I am uploading the existing context.xml. Error is same – Willy Oct 26 '15 at 15:50
  • Plz show us the context.xml – Richard Osseweyer Oct 26 '15 at 16:33

1 Answers1

0

Try

type="javax.sql.DataSource"

Instead of

type="javax.sql.ConnectionPoolDataSource"

See also this post: DataSource or ConnectionPoolDataSource for Application Server JDBC resources

Community
  • 1
  • 1
Richard Osseweyer
  • 1,693
  • 20
  • 25
  • Actually I have done it before posting here but I did again from scratch to ensure but it didn't help. DataSource invalid: "java.sql.SQLException: Cannot create PoolableConnectionFactory (Unknown database 'connpool')" – Willy Oct 26 '15 at 17:51
  • Ok actually it works after correcting database name. Thanks for your help acdhirr – Willy Oct 26 '15 at 18:10