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 August 28th, 2003, 09:18 PM
Registered User
 
Join Date: Aug 2003
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default Invalid authorization specification

i have been in and out of a ton of forums looking for the answer to this question, I really hope someone can help. I am getting this error wile trying to finish chapter 15 ex. :

SQLException: java.sql.SQLException: Invalid authorization specification: Access denied for user: 'username@localhost' (Using password: YES)

if i log into mysql and use the username and password i have in the CreateTable file it works fine, but for some reason when i run the file it doesnt. Please help,


 
Old August 29th, 2003, 09:12 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 175
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I don't know too much about MySQL, but you might be getting confused between Authentication and authorization.

Authentication is the process of validating that you are who you say you are. i.e. username & password.

Authorization checks the database access control list to make sure that you have permission to perform the data activity that you are attempting.

You might want to try using the administrator logon and password, which you can verify by using MySQL_GUI.

I appologise if you already know this.

Regards

Martyn
 
Old August 29th, 2003, 09:46 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 175
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Whoops! Like the fool that I am I went and originally posted this reply as a new topic. Sorry guys! Anyway, I've been thing about your problem and here a few other thoings to try:

When you log into the database form the console the hostname is 127.0.0.1 and when Tomcat logs into the database it uses the host localhost. Make sure that you have both hostnames listed in the user-table (I know people have solved this solved this by setting the host-name to '%'). You could also try to use the URL jdbc:mysql://127.0.0.1/etc.

GRANT ALL ON dbname.* TO "username"@hostname IDENTIFIED BY "password"

Confirm that you have the correct password in the connection string. Also, check the spelling and the case. Use something like this:

getConnection( "jdbc:mysql://localhost/mydbname", "myusername", "mypassword" );


Good luck....

Martyn
 
Old August 29th, 2003, 11:23 PM
Registered User
 
Join Date: Aug 2003
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks, let me try some of your suggestions, and let you know ...

 
Old August 29th, 2003, 11:42 PM
Registered User
 
Join Date: Aug 2003
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Still not working...

here is my code:

import java.sql.*;

public class CreateTable {
    public static void main(String args[]) {
    Connection con = null;
    try {

        Class.forName("org.gjt.mm.mysql.Driver").newInstan ce();
        System.out.println("JDBC driver Loaded Dude");
        con = DriverManager.getConnection(
        "jdbc:mysql://localhost/wrox?user=root&password=richard");
        System.out.println("Database connection established");

        Statement stmt = con.createStatement();
        String upd = "Create Table Author (Author_ID INTEGER NOT NULL PRIMARY KEY,Author_Name CHAR(50));";
        stmt.executeUpdate(upd);
        System.out.println("Table - Author Created");

        upd = "Create Table Category (Category_ID INTEGER NOT NULL PRIMARY KEY,Category_Description CHAR(50));";

        stmt.executeUpdate(upd);
        System.out.println("Table - Category Created");

        upd = "Create Table Contribution (Contribution_ID INTEGER NOT NULL PRIMARY KEY,Contribution_Description CHAR(50));";

        stmt.executeUpdate(upd);
        System.out.println("Table - Contribution Created");

    } catch (ClassNotFoundException cnfe) {
        System.out.println("ClassNotFoundException: Could not locate driver");

    } catch (SQLException cnfe) {
        System.out.println("SQLException: "+cnfe);

    } catch (Exception e) {
        System.out.println("An unknown error occured while connecting to the database");

    } finally {
        try {
            if ( con != null)
            con.close();
    } catch(SQLException sqle) {
        System.out.println("Unable to close database connection.");
    }
       }
      }
   }



I tried to replace localhost with 127.0.0.1 but that did not work either. this is the error that i get:

JDBC driver Loaded
SQLException: java.sql.SQLException: Invalid authorization specification: Access
 denied for user: 'username@localhost' (Using password: YES)

I am wondering, is the username@localhost really the word "username" or are they referring to root, ??



 
Old August 30th, 2003, 12:20 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 175
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Sorry, no offence meant but I had to smile. You need to enter the user name that you have set up in your database, or you could do as you suggested and use root, but deffinately not 'username'. The book you are using ought to have made that clear. If you are not sure have a look in the mysql database for table user.

I hope this sorts you out, but if not, I'm going away on a trip for a week but I'll gladly help on my return if you haven't sorted it, but I'm pretty confident that you will.

Cheers

Martyn
 
Old August 30th, 2003, 12:46 PM
Registered User
 
Join Date: Aug 2003
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

well i am using root as my username, what I meant was, in the error message is says username@localhost, not root@localhost, and i dont know why. In my code example i have user=root.

 
Old August 30th, 2003, 05:53 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 175
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi,

I've just load and ran your code and it worked pefectly. The only change i made was to the connection statement, changinfg the database to one that all ready exists and to my username & password combination:

con = DriverManager.getConnection(
        "jdbc:mysql://localhost/test?user=root&password=admin");


As you can see, all I've changed is the database and the password. Have a look at your set-up as that is obviously where your problem is. I'm still bettting that it is your username/password combination, but as a last minute thought, have you created the database 'wrox' and granted permission to root to access this db?

Good luck... I'm off on my holiday now. See you in a week!

Martyn
 
Old September 2nd, 2003, 07:30 PM
Registered User
 
Join Date: Aug 2003
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Martyn,

I have tried creating new databases, and that does not work. I have downloaded the mysql gui and thought that might help, but still nothing. I am almost at a quit point, but I need to know what it is that is wrong. Thanks for your suggestions. My real question is why does it say 'username@localhost' (Using password: YES). I dont know where it gets these words, I could change the localhost to some ip and it still says localhost. Also, can i just set the mysql to no password, to just make this thing work??

Thanks

Rick

 
Old September 7th, 2003, 12:52 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 175
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Rick,

Sorry for the delay in replying but I've only just got back from my holiday.

As I mentioned previously, your code runs fine on my machine, which leads me to reiterate that it must be a privilage thing. When you used mysql_gui did you check to ensure that you had suffucent privileges to access the data base? Check both localhost and \% in table users and also check the database access privileges in table db, which should all be 'Y'.

Let me know what settings you have and if this doesn't work then we can go thru it step by step, starting with creating a new user, database, table, etc.

Cheers

Martyn





Similar Threads
Thread Thread Starter Forum Replies Last Post
Chapter 8,Invalid authorization omom2002 BOOK: Beginning VB.NET Databases 1 May 27th, 2008 05:04 AM
Computed Column Specification olisav ASP.NET 2.0 Basics 0 May 14th, 2007 04:00 PM
Invalid specification file object in asp vlong77 ASP.NET 1.0 and 1.1 Basics 1 February 10th, 2006 08:03 PM
Bounce-path Specification pavanp .NET Web Services 0 February 1st, 2005 10:39 AM
Generic Type specification during runtime ChronicCode .NET Framework 2.0 0 December 2nd, 2004 12:55 AM





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