-1

showing error:-

Tue Apr 09 14:34:46 IST 2019 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.


java.sql.SQLException: Access denied for user 'sql12287303'@'localhost' (using password: YES)

I'm successed with using databases in my local machine, but I can't connect to my remote mysql server.

public class JDBCDemo {

    public static void main(String[] args) {
        String TableName;
        // TODO Auto-generated method stub
        try{
            String url="jdbc:mysql://localhost:3306/sql12287303";           //3306/db1?autoReconnect=true&useSSL=false";
            String username="sql12287303";
            String password="54hBDtsfPg";
            Class.forName("com.mysql.jdbc.Driver").newInstance();
            Connection con = DriverManager.getConnection(url, username, password);
            System.out.println ("Database connection established");
            System.out.println(con);
            Statement smt = con.createStatement();
            smt.execute("create database db1");
            smt.execute("use db1");
            smt.execute("create table flames(id Integer primary key,fname varchar(20),sname varchar(20)");
            smt.execute("show tables");

            ResultSet rs = smt.getResultSet();
            while(rs.next()){
                TableName = rs.getString(1);
                System.out.println("Table Name:"+TableName);
            }

        }catch(Exception e){System.out.println(e);} 
    }

}

TableName:flames

Purna Mahesh
  • 93
  • 1
  • 7
  • This is the same problem reported https://stackoverflow.com/questions/34189756/warning-about-ssl-connection-when-connecting-to-mysql-database – George Apr 09 '19 at 09:39
  • 1
    Hi Purna! Have you granted access to the user? `grant all on sql12287303.* to 'sql12287303'@'localhost' identified by '54hBDtsfPg'` – haba713 Apr 09 '19 at 09:40
  • @George It certainly is not. That's a warning: this is an error. That's an unauthenticated server: this is an unauthenticated client. Totally different situations. – user207421 Apr 09 '19 at 09:44
  • Your `url` references `localhost`. Is that what you want? I'm guessing that since you say "remote mysql" that it isn't. – guest Apr 09 '19 at 15:07
  • @guest Good point but he didn't get a connection refusal, he got an access denial, which means he got a connection. – user207421 Apr 09 '19 at 23:41
  • @OP Why is the username the same as the database name? – user207421 Apr 09 '19 at 23:41
  • Server: sql12.freemysqlhosting.net Name: sql12287303 Username: sql12287303 Password: 54hBDtsfPg Port number: 3306. There are generated in freemysqlhosting.net when I created database in it. – Purna Mahesh Apr 10 '19 at 15:32
  • The same error occurred while I'm accessing my database created in 000webhost – Purna Mahesh Apr 10 '19 at 15:34

1 Answers1

0

I guess a hint wasn't sufficient.

This code directs the JDBC driver to connect to a database named sql12287303 on localhost:

String url="jdbc:mysql://localhost:3306/sql12287303";

Your reported error indicates that you are, in fact, connecting to localhost, but with a user that is not known on the database server running there.

If you want to connect to a remote database, you need to change your URL:

String url="jdbc:mysql://sql12.freemysqlhosting.net:3306/sql12287303";
guest
  • 617
  • 4
  • 4