Results 1 to 5 of 5

Thread: Java & mysql error

  1. #1
    Join Date
    Jan 2009
    Location
    Denmark
    Beans
    Hidden!
    Distro
    Ubuntu 12.04 Precise Pangolin

    Java & mysql error

    Hoping you guys can help me.

    I have a mysql server, and installed phpmyadmin to administrate it.
    I have created a user for my local lan with the name "cristian" and password of "kage" with the host of "%", with no global PRIVILEGES
    I have then added all database specific privileges for the user.

    But when i try and connect to the database i get an error as follows
    com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorEx ception: Access denied for user 'cristian'@'%' to database 'jsp_testDB;'
    Code:
    public class ClassOne {
        public static void main(String[] args) {
            
            Connection connection = null;
            
            try {
                Class.forName("com.mysql.jdbc.Driver");
                connection = DriverManager.getConnection("jdbc:mysql://192.168.0.251:3306/jsp_testDB;", "cristian", "kage");
                
                if(!connection.isClosed()){
                    System.out.println("Connection ok");
                }
                
            } catch (ClassNotFoundException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (SQLException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
    }
    I am using
    Eclipse Java EE IDE for Web Developers.

    Version: Kepler Service Release 2
    Build id: 20140224-0627
    And got a JDBC file "mysql-connector-java-5.1.29-bin.jar" in my "Referenced Libraries".

    I have checked that my mysql service is listening on the TCP/IP connection on the servers ip address and not 127.0.0.1
    netstat -lnp | grep mysql
    tcp 0 0 192.168.0.251:3306 0.0.0.0:* LISTEN 10582/mysqld
    unix 2 [ ACC ] STREAM LISTENING 16533 10582/mysqld /var/run/mysqld/mysqld.sock
    But are running out of google searches to why i get this error.
    Hope someone can help me out a bit.
    Last edited by Drenriza; March 21st, 2014 at 03:42 PM.

  2. #2
    Join Date
    Aug 2010
    Location
    Lancs, United Kingdom
    Beans
    1,588
    Distro
    Ubuntu Mate 16.04 Xenial Xerus

    Re: Java & mysql error

    I'm not sure what the right syntax should be for passing the user and password to jdbc, but MySQL isn't seeing them. "(using password: NO)" means that no password has been supplied. "for user ''@'192.168.0.11'" also means that no user has been supplied, because you should get "for user 'cristian'@'192.168.0.11'".

  3. #3
    Join Date
    Jan 2009
    Location
    Denmark
    Beans
    Hidden!
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: Java & mysql error

    Edited it to
    Code:
    connection = DriverManager.getConnection("jdbc:mysql://192.168.0.251:3306/jsp_testDB;", "cristian", "kage");
    And now i get this error.
    com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorEx ception: Access denied for user 'cristian'@'%' to database 'jsp_testDB;'
    So now i guess it sees the username and password but wont allow access because... I dont know
    Last edited by Drenriza; March 21st, 2014 at 03:41 PM.

  4. #4
    Join Date
    Aug 2010
    Location
    Lancs, United Kingdom
    Beans
    1,588
    Distro
    Ubuntu Mate 16.04 Xenial Xerus

    Re: Java & mysql error

    It could be that semicolon at the end of the database name. Sorry I didn't spot that before.

  5. #5
    Join Date
    Jan 2009
    Location
    Denmark
    Beans
    Hidden!
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: Java & mysql error

    Quote Originally Posted by spjackson View Post
    It could be that semicolon at the end of the database name. Sorry I didn't spot that before.
    hhhhaaaaalijula Halijula Hhhaaallliiiijjjjjuuullllaaaa

    Thanks ,)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •