Wrox Programmer Forums
|
JSP Basics Beginning-level questions on JSP. More advanced coders should post to Pro JSP.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the JSP Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 26th, 2003, 09:02 AM
Registered User
 
Join Date: Jul 2003
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default JDBC


I have followed the book example but there is an error showed up. Please give me the idea how to solve it. Thanks a lot.

Here is the coding:

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

<sql:setDataSource var="datasource"
           driver="com.mysql.jdbc.Driver"
           url="jdbc:mysql://localhost/publish"
           user="phirun" password="amazon" />

<c:if test="${param.title != null}">
    <sql:update dataSource="${dataSource}">
    INSERT INTO book (title,price) values(?,?)
    <sql:param value="$(param.title)"/>
    <sql:param value="$(param.price)"/>
    </sql:update>
</c:if>
<sql:query var="books" dataSource="${datasource}">
    select id,title,price from book
</sql:query>

<html>
  <head>
     <title> A first JSP database </title>
  </head>
  <body>
    <form method="post">
    <table border="1">
      <tr>
        <td> id </td>
    <td> title </td>
    <td> price </td>
      </tr>
      <c:forEach items="${books.rows}" var="row">
      <tr>
    <td> <c:out value="${row.id}" /> </td>
    <td> <c:out value="${row.title}" /> </td>
    <td> <c:out value="${row.price}" /> </td>
      </tr>
      </c:forEach>
    <tr>
      <td> &nbsp; </td>
      <td> <input type="text" name="title" size="30" /> </td>
      <td> <input type="text" name="price" size="5" /> </td>
    </tr>
    <tr>
       <td colspan="3" align="center">
       <input type="submit" value="Save" />
       </td>
     </tr>

    </table>
</form>
 </body>
 </html>


This is the error which i got:


type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

org.apache.jasper.JasperException: The absolute uri: htt://java.sun.com/jstl/sql_rt cannot be resolved in either web.xml or the jar files deployed with this application
at org.apache.jasper.compiler.DefaultErrorHandler.jsp Error(DefaultErrorHandler.java:94)
at org.apache.jasper.compiler.ErrorDispatcher.dispatc h(ErrorDispatcher.java:365)
at org.apache.jasper.compiler.ErrorDispatcher.jspErro r(ErrorDispatcher.java:151)
at org.apache.jasper.compiler.TagLibraryInfoImpl.gene rateTLDLocation(TagLibraryInfoImpl.java:343)
at org.apache.jasper.compiler.TagLibraryInfoImpl.(Tag LibraryInfoImpl.java:170)
at org.apache.jasper.compiler.Parser.parseTaglibDirec tive(Parser.java:456)
at org.apache.jasper.compiler.Parser.parseDirective(P arser.java:517)
at org.apache.jasper.compiler.Parser.parseElements(Pa rser.java:1567)
at org.apache.jasper.compiler.Parser.parse(Parser.jav a:174)
at org.apache.jasper.compiler.ParserController.parse( ParserController.java:254)
at org.apache.jasper.compiler.ParserController.parse( ParserController.java:154)
at org.apache.jasper.compiler.ParserController.parse( ParserController.java:140)
at org.apache.jasper.compiler.Compiler.generateJava(C ompiler.java:250)
at org.apache.jasper.compiler.Compiler.compile(Compil er.java:458)
at org.apache.jasper.compiler.Compiler.compile(Compil er.java:444)
at org.apache.jasper.JspCompilationContext.compile(Js pCompilationContext.java:603)
at org.apache.jasper.servlet.JspServletWrapper.servic e(JspServletWrapper.java:300)
at org.apache.jasper.servlet.JspServlet.serviceJspFil e(JspServlet.java:293)
at org.apache.jasper.servlet.JspServlet.service(JspSe rvlet.java:240)
at javax.servlet.http.HttpServlet.service(HttpServlet .java:856)
at org.apache.catalina.core.ApplicationFilterChain.in ternalDoFilter(ApplicationFilterChain.java:286)
at org.apache.catalina.core.ApplicationFilterChain.do Filter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invo ke(StandardWrapperValve.java:256)
at org.apache.catalina.core.StandardValveContext.invo keNext(StandardValveContext.java:151)
at org.apache.catalina.core.StandardPipeline.invoke(S tandardPipeline.java:562)
at org.apache.catalina.core.ContainerBase.invoke(Cont ainerBase.java:974)
at org.apache.catalina.core.StandardContextValve.invo ke(StandardContextValve.java:205)
at org.apache.catalina.core.StandardValveContext.invo keNext(StandardValveContext.java:151)
at org.apache.catalina.core.StandardPipeline.invoke(S tandardPipeline.java:562)
at org.apache.catalina.core.ContainerBase.invoke(Cont ainerBase.java:974)
at org.apache.catalina.core.StandardHostValve.invoke( StandardHostValve.java:177)
at org.apache.catalina.core.StandardValveContext.invo keNext(StandardValveContext.java:151)
at org.apache.catalina.valves.ErrorDispatcherValve.in voke(ErrorDispatcherValve.java:171)
at org.apache.catalina.core.StandardValveContext.invo keNext(StandardValveContext.java:149)
at org.apache.catalina.valves.ErrorReportValve.invoke (ErrorReportValve.java:172)
at org.apache.catalina.core.StandardValveContext.invo keNext(StandardValveContext.java:149)
at org.apache.catalina.core.StandardPipeline.invoke(S tandardPipeline.java:562)
at org.apache.catalina.core.ContainerBase.invoke(Cont ainerBase.java:974)
at org.apache.catalina.core.StandardEngineValve.invok e(StandardEngineValve.java:156)
at org.apache.catalina.core.StandardValveContext.invo keNext(StandardValveContext.java:151)
at org.apache.catalina.core.StandardPipeline.invoke(S tandardPipeline.java:562)
at org.apache.catalina.core.ContainerBase.invoke(Cont ainerBase.java:974)
at org.apache.coyote.tomcat5.CoyoteAdapter.service(Co yoteAdapter.java:203)
at org.apache.coyote.http11.Http11Processor.process(H ttp11Processor.java:637)
at org.apache.coyote.http11.Http11Protocol$Http11Conn ectionHandler.processConnection(Http11Protocol.jav a:488)
at org.apache.tomcat.util.net.TcpWorkerThread.runIt(P oolTcpEndpoint.java:568)
at org.apache.tomcat.util.threads.ThreadPool$ControlR unnable.run(ThreadPool.java:631)
at java.lang.Thread.run(Unknown Source)


 
Old July 28th, 2003, 01:08 AM
Registered User
 
Join Date: Jul 2003
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Have you tried re-typing the whole program again?

 
Old July 28th, 2003, 03:38 AM
Registered User
 
Join Date: Jun 2003
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Dear nishant,

look at line 4 :

<sql:setDataSource var="datasource" ...

you can also assign any name to var. For eg: mysqlDataSource.

Then go to line 10. In statement:

<sql:update dataSource="${dataSource}">

change to <sql:update dataSource="${[u]mysqlDataSource</u>}">

Get it? It just a typo error. Be careful next time and read the whole code again to check if there are more typing error.

OK.
 
Old July 30th, 2003, 02:58 AM
Registered User
 
Join Date: Jul 2003
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

well i changed the var names but it dint help.

ck out this code:

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

<%@ taglib uri="htt://java.sun.com/jstl/sql_rt" prefix="sql" %>

<sql:setDataSource var="mysqlDataSource"
        driver="com.mysql.jdbc.Driver"
        url="jdbc:mysql://localhost/publish"
user="nishant" password="icanttellyou" />

<sql:query var="books" dataSource="${mysqlDataSource}">
SELECT id,title,price FROM book

</sql:query>

<html>
<head>
<title>A first JSP database</title>
</head>

<body>
    <table border="1">
    <tr>
    <td>id</td><td>title</td><td>price</td>
    </tr>
    <c:forEach items="${books.rows}" var="row">
    <tr>
    <td><c:out value="${row.id}" /></td>
    <td><c:out value="${row.title}" /></td>
    <td><c:out value="${row.price}" /></td>
    </tr>
    </c:forEach>
    </table>
</body>
</html>


the error is same as i posted.

Quote:
quote:Originally posted by mrkhairy
 Dear nishant,

look at line 4 :

<sql:setDataSource var="datasource" ...

you can also assign any name to var. For eg: mysqlDataSource.

Then go to line 10. In statement:

<sql:update dataSource="${dataSource}">

change to <sql:update dataSource="${[u]mysqlDataSource</u>}">

Get it? It just a typo error. Be careful next time and read the whole code again to check if there are more typing error.

OK.
 
Old July 30th, 2003, 03:57 AM
Registered User
 
Join Date: Jun 2003
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default

dear nishant,

Are you sure your code is correct? You mispelled http: at line 3.

<%@ taglib uri="htt://java.sun.com/jstl/sql_rt" prefix="sql" %>

If you have change the code and the error still occur, replace all the runtimes above with :

<%@ taglib uri="http://java.sun.com/jstl/sql" prefix="sql" %>
<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %>
 
Old August 9th, 2003, 01:58 AM
Registered User
 
Join Date: Jul 2003
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

My previous error was corrected but this is the new erroe i am getting.

type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

javax.servlet.ServletException: Unable to get connection, DataSource invalid: "No suitable driver"
at org.apache.jasper.runtime.PageContextImpl.handlePa geException(PageContextImpl.java:682)
at org.apache.jsp.bookdb_jsp._jspService(bookdb_jsp.j ava:94)
at org.apache.jasper.runtime.HttpJspBase.service(Http JspBase.java:136)
at javax.servlet.http.HttpServlet.service(HttpServlet .java:856)
at org.apache.jasper.servlet.JspServletWrapper.servic e(JspServletWrapper.java:320)
at org.apache.jasper.servlet.JspServlet.serviceJspFil e(JspServlet.java:293)
at org.apache.jasper.servlet.JspServlet.service(JspSe rvlet.java:240)
at javax.servlet.http.HttpServlet.service(HttpServlet .java:856)
at org.apache.catalina.core.ApplicationFilterChain.in ternalDoFilter(ApplicationFilterChain.java:286)
at org.apache.catalina.core.ApplicationFilterChain.do Filter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invo ke(StandardWrapperValve.java:256)
at org.apache.catalina.core.StandardValveContext.invo keNext(StandardValveContext.java:151)
at org.apache.catalina.core.StandardPipeline.invoke(S tandardPipeline.java:562)
at org.apache.catalina.core.ContainerBase.invoke(Cont ainerBase.java:974)
at org.apache.catalina.core.StandardContextValve.invo ke(StandardContextValve.java:205)
at org.apache.catalina.core.StandardValveContext.invo keNext(StandardValveContext.java:151)
at org.apache.catalina.core.StandardPipeline.invoke(S tandardPipeline.java:562)
at org.apache.catalina.core.ContainerBase.invoke(Cont ainerBase.java:974)
at org.apache.catalina.core.StandardHostValve.invoke( StandardHostValve.java:177)
at org.apache.catalina.core.StandardValveContext.invo keNext(StandardValveContext.java:151)
at org.apache.catalina.valves.ErrorDispatcherValve.in voke(ErrorDispatcherValve.java:171)
at org.apache.catalina.core.StandardValveContext.invo keNext(StandardValveContext.java:149)
at org.apache.catalina.valves.ErrorReportValve.invoke (ErrorReportValve.java:172)
at org.apache.catalina.core.StandardValveContext.invo keNext(StandardValveContext.java:149)
at org.apache.catalina.core.StandardPipeline.invoke(S tandardPipeline.java:562)
at org.apache.catalina.core.ContainerBase.invoke(Cont ainerBase.java:974)
at org.apache.catalina.core.StandardEngineValve.invok e(StandardEngineValve.java:156)
at org.apache.catalina.core.StandardValveContext.invo keNext(StandardValveContext.java:151)
at org.apache.catalina.core.StandardPipeline.invoke(S tandardPipeline.java:562)
at org.apache.catalina.core.ContainerBase.invoke(Cont ainerBase.java:974)
at org.apache.coyote.tomcat5.CoyoteAdapter.service(Co yoteAdapter.java:203)
at org.apache.coyote.http11.Http11Processor.process(H ttp11Processor.java:637)
at org.apache.coyote.http11.Http11Protocol$Http11Conn ectionHandler.processConnection(Http11Protocol.jav a:488)
at org.apache.tomcat.util.net.TcpWorkerThread.runIt(P oolTcpEndpoint.java:568)
at org.apache.tomcat.util.threads.ThreadPool$ControlR unnable.run(ThreadPool.java:631)
at java.lang.Thread.run(Unknown Source)

 
Old August 9th, 2003, 03:46 AM
Authorized User
 
Join Date: Aug 2003
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default

The problem is that Java's driver manager cannot find a suitable driver for jdbc:mysql: JDBC URIs. This means that com.mysql.jdbc.Driver failed to register, for example because you have not put the driver jar in the web application's /WEB-INF/lib directory.

Other causes could be a mistake in the URI or the driver name, although I didn't spot any here.

- Peter
 
Old August 9th, 2003, 03:42 PM
Registered User
 
Join Date: Jul 2003
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

i have the driver in the WEB-INF/lib directory. but i still get the same errror

 
Old August 10th, 2003, 03:58 PM
Authorized User
 
Join Date: Aug 2003
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Did you set it up as a proper web-app? But before we go into that, do this simple test first. Drop the driver jar in JAVA_HOME/jre/lib/ext. Restart the application server and see what happens. If that still doesn't work, it's one of (a) the driver jar is corrupt (b) the driver name is mis-spelled (c) there is a mistake in the protocol name of the database uri.

If, on the other hand, that does work, there is a problem in the way you set up the web application and the server doesn't load the jars from WEB-INF/lib.

 - Peter

 
Old January 5th, 2004, 11:24 AM
Registered User
 
Join Date: Jan 2004
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I had to change the URIs in the taglib statements to http://java.sun.com/jsp/jstl/core and http://java.sun.com/jsp/jstl/sql. After that all worked for me.







Similar Threads
Thread Thread Starter Forum Replies Last Post
JDBC 4.0 billfly BOOK: Professional Java, JDK 6 Edition ISBN: 978-0-471-77710-6 2 February 11th, 2007 10:53 AM
JDBC visva4u3 Java Databases 0 April 19th, 2006 06:35 AM
JDBC cooldude87801 BOOK: Beginning Java 2 2 July 30th, 2004 01:08 AM
Cannot load JDBC driver class with com.mysql.jdbc. dzis Apache Tomcat 0 January 29th, 2004 11:57 AM
Cannot load JDBC driver class with com.mysql.jdbc. dzis MySQL 0 January 29th, 2004 11:31 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.