Search code examples
javaapplication-server

JAVA: JDBC Connection by URL Aurora(mysql) aws


i want to connect to a D by an URL i got to make the conections.

static Connection cnx = null;
public static Connection obtener() throws SQLException{
    if (cnx == null) {
        try {
            cnx = DriverManager.getConnection("jdbc:mysql://combis.cpgtn4fi7t5t.us-east-1.rds.amazonaws.com/am_myDataBase", "user", "pass");
        }catch (SQLException es) {
            // TODO: handle exception
            throw new SQLException(es);
        }
    }
    return cnx;
}

and i can not get the connection. Is it well written the URL? got this Error:

java.sql.SQLException: java.sql.SQLException: No suitable driver found for jdbc:mysql://combis.cpgtn4fi7t5t.us-east-1.rds.amazonaws.com/am_myDataBase


Solution

  • I think, you need to do two things here that are:-

    1.Load the mysql driver class.

     Class.forName("com.mysql.jdbc.Driver");
    

    2.Change the connection url like this-

     jdbc:mysql://combis.cpgtn4fi7t5t.us-east-1.rds.amazonaws.com/am_myDataBase?useSSL=false
    

    I hope it will work.