GeeCON Prague 2014*
The moose likes JDBC and the fly likes How to get authorized using MySql? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Databases » JDBC
Bookmark "How to get authorized using MySql?" Watch "How to get authorized using MySql?" New topic
Author

How to get authorized using MySql?

Mark Lau
Ranch Hand

Joined: Dec 15, 2001
Posts: 120
I run MySql under Solaris 8 very well. I inserted a user called jack into the user table
of mysql database like this:
mysql>INSERT INTO user (Host, User, Password)
-> VALUES('localhost', 'jack', PASSWORD('johnson'));
Query OK, 1 row affected (0.00 sec)
I checked the table, and see that user jack is there.
Here is a part of my JDBC test code, which accesses the demodb database I have created for test use.
import java.net.*;
import java.sql.*;
import java.io.*;
import java.util.*;
class MySqlTest
{ public static void main(String [] args)
{ try
{ Class.forName ("org.gjt.mm.mysql.Driver");
java.sql.Connection con;
con=DriverManager.getConnection("jdbc:mysql://localhost/demodb", "jack", "johnson");
......
}
The code compiles successfully, but when I run the bytecode, I get an exception. Look here:
# java MySqlTest
java.sql.SQLException: Invalid authorization specification: Access denied for user: 'jack@localhost' (Using password: YES)
#

Don't worry about the driver. I think the driver is working well, otherwise, I would have got another exception concerning the driver.
So what is the problem? How should I fix it please?
Thanks a lot.
[ March 10, 2002: Message edited by: Gene Chao ]
Michael Yuan
author
Ranch Hand

Joined: Mar 07, 2002
Posts: 1427
You must add jack@localhost in your access table. In my system, the domain added by the commandline tool is "username@localhost.localdomain" or username@real_host_name
I suggest you to log in from the commandline utility and explicitly run the following:
mysql> GRANT ALL PRIVILEGES ON *.* TO jack@localhost IDENTIFIED BY 'some_pass' WITH GRANT OPTION;


Seam Framework: http://www.amazon.com/exec/obidos/ASIN/0137129394/mobileenterpr-20/
Ringful: http://www.ringful.com/
Mark Lau
Ranch Hand

Joined: Dec 15, 2001
Posts: 120
Thanks. How do I add that thing to the access table? What do you mean by access table? Are you referring to the user table of mysql database? Thanks.
Michael Yuan
author
Ranch Hand

Joined: Mar 07, 2002
Posts: 1427
Yes, I meant the user table. I think the above GRANT command should take care of this for you ...
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: How to get authorized using MySql?