• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Trouble in retrieving data from the mysql database using JSTL

 
Sanjeev Das
Greenhorn
Posts: 4
Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I am a newbie in using JSTL, so got stuck on a code where I need to retrieve the datas from a database without using any scripting code. I am using NetBEans IDE and mysql. I am using a user created database named as 'mydatabase' and a table named as 'events' which contains a column 'events' with lots of data in it.
So, the sql command Select events from mydatabase.events works fine.
A piece of my work goes below...is it made in an amaturish fashion?


Somehow, I keep receiving the exception message after the jsp page(sqlTest.jsp) is run.
The exception msg is:
javax.servlet.ServletException: javax.servlet.jsp.JspException: Unable to get connection, DataSource invalid: "java.sql.SQLException: No suitable driver found for jdbc:mysql://localhost:3306/mydatabase"
and the root cause is:
javax.servlet.jsp.JspException: Unable to get connection, DataSource invalid: "java.sql.SQLException: No suitable driver found for jdbc:mysql://localhost:3306/mydatabase"

However, I have imported the jar file MySQL JDBC Driver from the IDE's library to my project. The jar does contain the package com.mysql.jdbc with the Driver.class file. I also have the JSTL 1.1 and the standard.jar in my project. So everything is in place and I really dont know whats going wrong. The funny part is, the code works properly with the Derby database and its driver. So whats wrong with mysql's Driver???
 
Pete Nelson
Ranch Hand
Posts: 147
Debian Eclipse IDE Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You mentioned importing the mysql driver into your project - is that driver also exported into your WAR file's WEB-INF/lib folder?
 
Sanjeev Das
Greenhorn
Posts: 4
Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
thanks for the reply...appreciate that.
Oops, even by importing the mysql.jar into the WEB-INF/lib folder dsnt help...got the same exception.

 
Sanjeev Das
Greenhorn
Posts: 4
Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Any clues bout the issue... will b appreciated.
 
siva penmetsa
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i have the same problem.
i am using eclipse on ubuntu.
i did the same things but still error is there
any solution.?

My code

<%@ page language="java" import="java.lang.Class" %>
<%@ page language="java" import="java.sql.*" %>

<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jstl/sql" prefix="sql"%>

<sql:setDataSource var="dataSource" driver="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost:3306/student" user="root" password="innovate" />
<html>
<head>
<title>Query Example</title>
</head>
<body>
<sql:query var="users" dataSource="$dataSource">
select * from personal;
</sql:query>
<table>
<c:forEach var="row" items="$users">
<tr>
<td><cut value="$row.uname" /></td>
<td><cut value="$row.fname" /></td>
<td><cut value="$row.lname" /></td>
<td><cut value="$row.city" /></td>
<td><cut value="$row.mobile" /></td>
</tr>
</c:forEach>
</table>
</body>
</html>


I got the following errors:


javax.servlet.jsp.JspException: Unable to get connection, DataSource invalid: "java.sql.SQLException: No suitable driver found for $dataSource"
at org.apache.taglibs.standard.tag.common.sql.QueryTagSupport.getConnection(QueryTagSupport.java:314)
at org.apache.taglibs.standard.tag.common.sql.QueryTagSupport.doStartTag(QueryTagSupport.java:197)
at org.apache.taglibs.standard.tag.el.sql.QueryTag.doStartTag(QueryTag.java:123)
at org.apache.jsp.New_jsp._jspx_meth_sql_query_0(New_jsp.java from :140)
at org.apache.jsp.New_jsp._jspService(New_jsp.java from :82)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:109)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:847)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:406)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:483)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:373)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:847)
at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1523)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:279)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:188)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:641)
at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:97)
at com.sun.enterprise.web.PESessionLockingStandardPipeline.invoke(PESessionLockingStandardPipeline.java:85)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:185)
at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:325)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:226)
at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:165)
at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:791)
at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:693)
at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:954)
at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:170)
at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:135)
at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:102)
at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:88)
at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:76)
at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:53)
at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:57)
at com.sun.grizzly.ContextTask.run(ContextTask.java:69)
at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:330)
at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:309)
at java.lang.Thread.run(Thread.java:662)
Selection_004.png
[Thumbnail for Selection_004.png]
Selection_005.png
[Thumbnail for Selection_005.png]
 
Peter Johnson
author
Bartender
Posts: 5852
7
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try removing the dataSource="$dataSource" from the sql:query statement because, based on the error message, it appears that $datasource is not set. I don't think you need to specify a datasource for your sql statements if your code declares only one.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic