mysql - JDBC connection problem

Discussion in 'Java' started by Marcelo, Nov 22, 2005.

  1. Marcelo

    Marcelo Guest

    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
     
    Marcelo, Nov 22, 2005
    #1
    1. Advertising

  2. Marcelo

    Seamus Guest

    Marcelo wrote:
    > 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
     
    Seamus, Nov 22, 2005
    #2
    1. Advertising

  3. Marcelo

    Roedy Green Guest

    On Tue, 22 Nov 2005 17:21:34 +0100, Marcelo <> wrote,
    quoted or indirectly quoted someone who said :

    >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.
    --
    Canadian Mind Products, Roedy Green.
    http://mindprod.com Java custom programming, consulting and coaching.
     
    Roedy Green, Nov 22, 2005
    #3
  4. Marcelo

    Marcelo Guest

    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
     
    Marcelo, Nov 22, 2005
    #4
  5. Marcelo

    zero Guest

    Marcelo <> wrote in news:4383803a$:

    > 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.
     
    zero, Nov 22, 2005
    #5
  6. Marcelo

    Marcelo Guest

    Marcelo wrote:
    > 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");
     
    Marcelo, Nov 22, 2005
    #6
  7. Marcelo

    Marcelo Guest

    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
     
    Marcelo, Nov 22, 2005
    #7
  8. Marcelo

    Rhino Guest

    "Marcelo" <> wrote in message
    news:43838576$...
    > Marcelo wrote:
    >> 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");


    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
     
    Rhino, Nov 22, 2005
    #8
  9. Marcelo

    Marcelo Guest

    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
     
    Marcelo, Nov 22, 2005
    #9
  10. Marcelo

    Marcelo Guest

    Marcelo wrote:
    > 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 |
    +-----------+------------------+---------------+-------------+-----------------+
     
    Marcelo, Nov 22, 2005
    #10
  11. Marcelo

    Marcelo Guest

    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
     
    Marcelo, Nov 22, 2005
    #11
  12. Marcelo

    Roedy Green Guest

    On Tue, 22 Nov 2005 23:15:36 +0100, Marcelo <> wrote,
    quoted or indirectly quoted someone who said :

    >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.


    --
    Canadian Mind Products, Roedy Green.
    http://mindprod.com Java custom programming, consulting and coaching.
     
    Roedy Green, Nov 22, 2005
    #12
  13. Marcelo

    jonck Guest

    > 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.
     
    jonck, Nov 22, 2005
    #13
  14. Marcelo

    Rhino Guest

    "Marcelo" <> wrote in message
    news:43839887$...
    >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
     
    Rhino, Nov 23, 2005
    #14
  15. Marcelo

    Alun Harford Guest

    "Marcelo" <> wrote in message
    news:4383458d$...
    > 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
     
    Alun Harford, Nov 23, 2005
    #15
  16. Marcelo

    Alun Harford Guest

    "Alun Harford" <> wrote in message
    news:dm0g6e$b2a$...
    > "Marcelo" <> wrote in message
    > news:4383458d$...
    > > 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
    >


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

    Alun Harford
     
    Alun Harford, Nov 23, 2005
    #16
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Keith Wansbrough

    Re: jdbc help:sun.jdbc.odbc.JdbcOdbcDriver

    Keith Wansbrough, Aug 16, 2004, in forum: Java
    Replies:
    0
    Views:
    811
    Keith Wansbrough
    Aug 16, 2004
  2. Betty
    Replies:
    1
    Views:
    9,938
    Juha Laiho
    May 21, 2005
  3. bb

    JDBC, MySQL connection

    bb, Oct 26, 2005, in forum: Java
    Replies:
    4
    Views:
    6,169
    jonck
    Oct 26, 2005
  4. bruce
    Replies:
    19
    Views:
    1,242
    Tom Anderson
    Sep 24, 2010
  5. bruce

    JDBC connection to mysql

    bruce, Oct 21, 2010, in forum: Java
    Replies:
    3
    Views:
    427
    Roedy Green
    Oct 26, 2010
Loading...

Share This Page