mysql - JDBC connection problem

M

Marcelo

Dear all,

I am having a hard time connect mysql with Java.
I am using the code like this:

Connection db;
try {
db = DriverManager.getConnection("jdbc:mysql://localhost/project",
user, pass);
}

where project is my database.
There is no problem with the driver Class.forName("com.mysql.jdbc.Driver");

However, for some reason I get this error message:

java.sql.SQLException: null, message from server: "Host
'localhost.localdomain' is not allowed to connect to this MySQL server"

Should I specify a socket or something like that in order to reach a
connection to my localhost?

thanks for your help,

Marcelo
 
S

Seamus

Marcelo said:
Dear all,

I am having a hard time connect mysql with Java.
I am using the code like this:

Connection db;
try {
db = DriverManager.getConnection("jdbc:mysql://localhost/project",
user, pass);
}

where project is my database.
There is no problem with the driver Class.forName("com.mysql.jdbc.Driver");

However, for some reason I get this error message:

java.sql.SQLException: null, message from server: "Host
'localhost.localdomain' is not allowed to connect to this MySQL server"

Should I specify a socket or something like that in order to reach a
connection to my localhost?

thanks for your help,

Marcelo
Take a look at this thread on the mysql site :
http://forums.mysql.com/read.php?86,23619,41248#msg-41248
 
R

Roedy Green

java.sql.SQLException: null, message from server: "Host
'localhost.localdomain' is not allowed to connect to this MySQL server"

Should I specify a socket or something like that in order to reach a
connection to my localhost?

It sounds like you need some sort of GRANT statement to allow access
from that domain. I did not see a syntax for that though.
 
M

Marcelo

hi,

I am still having trouble with this connections. Even after using the
Grant command (with parameter ALL) it is impossible to accès to the
database.

I seems like localhost is not recognised.... (i have even tried
127.0.0.1 no difference).

I don't have any idea of how may be wrong....
if you have some ideas, please let me know

Marce
 
Z

zero

Marcelo said:
hi,

I am still having trouble with this connections. Even after using the
Grant command (with parameter ALL) it is impossible to accès to the
database.

I seems like localhost is not recognised.... (i have even tried
127.0.0.1 no difference).

I don't have any idea of how may be wrong....
if you have some ideas, please let me know

Marce

Who did you grant all privileges to?

It seems like your problem is with the MySQL administration, not Java. I
suggest you ask at a mysql group. Before you do, you could do some
testing, like trying to connect (from localhost of course) with the mysql
command line client.
 
M

Marcelo

Marcelo said:
hi,

I am still having trouble with this connections. Even after using the
Grant command (with parameter ALL) it is impossible to accès to the
database.

I seems like localhost is not recognised.... (i have even tried
127.0.0.1 no difference).

I don't have any idea of how may be wrong....
if you have some ideas, please let me know

Marce
I am using this driver, is it okay?
Class.forName("com.mysql.jdbc.Driver");
 
M

Marcelo

normally it works on command line

mysql -h localhost -u anyone -p any

On command line, no problem at all.
the grant privileges where given by the "root" user.

thanks

Marcelo
 
R

Rhino

Marcelo said:
I am using this driver, is it okay?
Class.forName("com.mysql.jdbc.Driver");

Yes, that is the correct JDBC driver to use for MySQL.

There are several MySQL mailing lists at this URL: http://lists.mysql.com/.
One of them is dedicated to Java/MySQL questions. You may want to check the
archive for that list to see if they've seen this problem before and have a
solution. I just looked and this problem has come up several times before
and the responders have suggested solutions.

However, if you try everything suggested in the archives and still have
problems, you can subscribe to the mailing list and describe your problem
there. One of the guys who responds to the questions on the MySQL/Java
mailing list is a guy named Mark Matthews who writes the JDBC drivers for
MySQL; he is very helpful. But many of the other responders there are also
very good.

I'm not going to tell you what the archives give as the solution for your
problem. If you are going to work with MySQL, it's a very good idea for you
to get familiar with the best ways to get help with MySQL problems; you
won't get that if I do all of the work :)


Rhino
 
M

Marcelo

I guess I have found the error, but I don't know well how to proceed (as
I am very new in SQL)

I guess there is a problem with the max_connections, max_updates values
at the mysql database given for the root

how to proceed know? (changing this value?)

thanks a lot,

Marcelo
 
M

Marcelo

Marcelo said:
I guess I have found the error, but I don't know well how to proceed (as
I am very new in SQL)

I guess there is a problem with the max_connections, max_updates values
at the mysql database given for the root

how to proceed know? (changing this value?)

thanks a lot,

Marcelo
+-----------+------------------+---------------+-------------+-----------------+
| host | user | max_questions | max_updates |
max_connections |
+-----------+------------------+---------------+-------------+-----------------+
| localhost | root | 0 | 0 |
0 |
| ubuntu | root | 0 | 0 |
0 |
| localhost | debian-sys-maint | 0 | 0 |
0 |
| localhost | anyone | 0 | 0 |
0 |
+-----------+------------------+---------------+-------------+-----------------+
 
M

Marcelo

I just wanna share this experience (it took me more than 3 hours :( )

there was no connection for two important reasons:
1.- the username created on localhost had as max_connections parameter = 0 (with other parameters) so when java wanted to connect to the mysql server, the connection has refused.

2.- for some reason that I don't understand, the localhost cannot be accessed by this java program
the error has:
java.sql.SQLException: null, message from server: "Host 'localhost.localdomain' is not allowed to connect to this MySQL server"

So I created the grants 'username'@'localhost.localdomain' and then, magickally, it worked. However, I don't understand why Mysql has asking for localhost.localdomain .....

thanks to everybody,
excellent help was given !!!!

Marcelo
 
R

Roedy Green

I don't understand why Mysql has asking for localhost.localdomain .

On what machine the JDBC driver running, the same one as the SQL
engine right? So to SQL, that program is just another ordinary user
calling in from localhost.localdomain. It treats local connections
the same as those coming in over the net.
 
J

jonck

1.- the username created on localhost had as max_connections
parameter = 0 (with other parameters) so when java wanted to
connect to the mysql server, the connection has refused.

No, this is not the cause of your problems. Contrary to what you might
think, having max_questions, max_updates and max_connections at 0 means
the user in question has unlimited questions, updates and connections.
 
R

Rhino

Marcelo said:
I just wanna share this experience (it took me more than 3 hours :( )

there was no connection for two important reasons:
1.- the username created on localhost had as max_connections parameter = 0
(with other parameters) so when java wanted to connect to the mysql
server, the connection has refused.

2.- for some reason that I don't understand, the localhost cannot be
accessed by this java program
the error has:
java.sql.SQLException: null, message from server: "Host
'localhost.localdomain' is not allowed to connect to this MySQL server"

So I created the grants 'username'@'localhost.localdomain' and then,
magickally, it worked. However, I don't understand why Mysql has asking
for localhost.localdomain .....



This is explained in the archived posts that I mentioned in my original
reply to your question....



thanks to everybody,
excellent help was given !!!!

Marcelo
Rhino
 
A

Alun Harford

Marcelo said:
Dear all,

I am having a hard time connect mysql with Java.
I am using the code like this:

Connection db;
try {
db = DriverManager.getConnection("jdbc:mysql://localhost/project",
user, pass);
}

where project is my database.
There is no problem with the driver Class.forName("com.mysql.jdbc.Driver");

However, for some reason I get this error message:

java.sql.SQLException: null, message from server: "Host
'localhost.localdomain' is not allowed to connect to this MySQL server"

Did you forget to give it your password?
jdbc:mysql://localhost/project?user=USERNAME&password=PASSWORD

Alun Harford
 
A

Alun Harford

Alun Harford said:
Did you forget to give it your password?
jdbc:mysql://localhost/project?user=USERNAME&password=PASSWORD

Alun Harford

Oh wait...
That was a dumb post (although it still looks like a password issue to me)

Alun Harford
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,968
Messages
2,570,153
Members
46,699
Latest member
AnneRosen

Latest Threads

Top