Skip navigation links

MySQL Forums :: Connector/JDBC and Java :: Getting error when trying to communicate MySQL to Tomcat


Advanced Search

Getting error when trying to communicate MySQL to Tomcat
Posted by: Jack Luk ()
Date: March 17, 2012 08:55AM

Hi,

I am very new to MYSQL and Tomcat. I have some programming experience and I recently have an idea to start a website. So here I am getting stuck at the part where I try to get Tomcat to communicate with MySQL. Also please forgive me when I get terminologies wrong - I might call things classes when they are objects or apples when they are oranges so please bear with me, I am still learning.


I have bought this book Beginning Jsp, Jsf and Tomcat Web Development. It give me instructions on setting up this "shop" database in Mysql and the book tells me to run a test in Tomcat to see if the two are communicating.

So I have set up a shop database in MYSQL and I can see that what I put in is correct because I can find my data in a table format when I "query" it.

now I run the following JSP code to display a page in Tomcat but I get this error message and I can't figure out what I'm doing wrong. The book made it seem like this process should have given me no problem.


This is the first 6 lines of the code....The error kicks in at line 6.

<%@page language="java" contentType="text/html"%>
<%@page import="java.sql.*"%>
<html><head><title>JDBC test</title></head><body>
<%
Class.forName("com.mysql.jdbc.Driver");
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/shop", "root", "");

Below is the error message I am getting from Tomcat.Any help would be greatly appreciated!. I feel like this is a simple definition problem, but I just don't know where to start tackling this!

Thanks Very much.
Wai

HTTP Status 500 -

type Exception report

message

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 /tests/jdbc.jsp at line 6

3: <html><head><title>JDBC test</title></head><body>
4: <%
5: Class.forName("com.mysql.jdbc.Driver");
6: Connection conn = DriverManager.getConnection(
7: "jdbc:mysql://localhost:3306/shop", "root", "");
8: Statement stmt = conn.createStatement();
9: ResultSet rs = stmt.executeQuery("select * from books");


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:390)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)

root cause

javax.servlet.ServletException: java.sql.SQLException: Access denied for user 'root'@'localhost' (using password: NO)
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:911)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:840)
org.apache.jsp.tests.jdbc_jsp._jspService(jdbc_jsp.java:109)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)

root cause

java.sql.SQLException: Access denied for user 'root'@'localhost' (using password: NO)
com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1073)
com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3609)
com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3541)
com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:943)
com.mysql.jdbc.MysqlIO.secureAuth411(MysqlIO.java:4113)
com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1308)
com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2336)
com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2369)
com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2153)
com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:792)
com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:47)
sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
java.lang.reflect.Constructor.newInstance(Unknown Source)
com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:381)
com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:305)
java.sql.DriverManager.getConnection(Unknown Source)
java.sql.DriverManager.getConnection(Unknown Source)
org.apache.jsp.tests.jdbc_jsp._jspService(jdbc_jsp.java:68)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)

Options: ReplyQuote


Subject Written By Posted
Getting error when trying to communicate MySQL to Tomcat Jack Luk 03/17/2012 08:55AM
Re: Getting error when trying to communicate MySQL to Tomcat Peter Brawley 03/17/2012 09:10AM
Re: Getting error when trying to communicate MySQL to Tomcat Todd Farmer 03/19/2012 01:42PM
Re: Getting error when trying to communicate MySQL to Tomcat Jack Luk 03/19/2012 10:26PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.