Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Java > Java and JDK > JSP Basics
|
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 January 31st, 2004, 02:02 PM
Registered User
 
Join Date: Jan 2004
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default Can't connect to MySQL using JSTL tag

I am trying to display data using JSTL SQL tags as instructed on page 91 (Beginning JSP 2.0), and I got the following error message :
Code:
javax.servlet.ServletException: Unable to get connection, DataSource invalid: "java.sql.SQLException: Invalid authorization specification,  message from server: "Access denied for user: 'gabriel@localhost.localdomain' (Using password: YES)""
    org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:867)
    org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:800)
    org.apache.jsp.pizza.bookDB_jsp._jspService(bookDB_jsp.java:91)
    org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:133)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:311)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:301)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:248)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:856)


Below is my source code :

Code:
<%@ 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/ebusiness"
                  user="gabriel" password="xxx" />

<sql:query var="books" dataSource="${datasource}">
    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="${book.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>
I have granted all privilege to "gabriel" user in mysql by:
Code:
mysql> use ebusiness
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
 
Database changed
mysql> grant all privileges on ebusiness to gabriel@localhost.localdomain identified by 'xxx';
Query OK, 0 rows affected (0.11 sec)
Please help....

 
Old January 31st, 2004, 03:04 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 175
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Try using the IP address instead of the host name. e.g. 127.0.0.1 instead of localhost.

Cheers

Martyn
 
Old January 31st, 2004, 04:01 PM
Registered User
 
Join Date: Jan 2004
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I changed the hostname with the IP address but still having the same error message.

 
Old January 31st, 2004, 05:04 PM
Registered User
 
Join Date: Jan 2004
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I finally got it to work. :-)

In my /etc/hosts file, I have this configuration :
Code:
127.0.0.1    localhost.localdomain    localhost
Although in the JSTL tag, I put :
Code:
url="jdbc:mysql://localhost/ebusines
Somehow, the JSTL tried to connect to user gabriel@localhost.localdomain that does not exist in mysql.
So I created a new user gabriel@localhost.localdomain, and everything works just fine... :-)

Thanks for your help, Martyn...
and






Similar Threads
Thread Thread Starter Forum Replies Last Post
Unable connect to MySQL using JSTL tag PatrickWalsh JSP Basics 12 December 15th, 2004 01:41 PM
Trying to connect to Mysql tp194 Classic ASP Databases 4 November 11th, 2004 12:12 AM
Best way to connect to mySQL netdaviso Java Databases 1 April 5th, 2004 06:37 AM





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