1
I’m trying to make a connection with the Elephantsql (postgres) through java. With the same code I was able to connect to the local postgres (just changing the url, user, password). I’m trying to do it like this:
private static final String DRIVER = "org.postgresql.Driver";
private static final String URL = "jdbc:postgres://nklbcxow:[email protected]:5432/nklbcxow";
private static final String USER = "nklbcxow";
private static final String PASS = "MINHA_SENHA_NO_ELEPHANTSQL";
public static Connection getConnection() throws SQLException {
try {
Class.forName(DRIVER);
return DriverManager.getConnection(URL, USER, PASS);
} catch (ClassNotFoundException ex) {
throw new RuntimeException("Erro na conexão", ex);
}
}
But there’s a driver error:
Exception in thread "main" java.sql.Sqlexception: No suitable driver found for jdbc:postgres://nklbcxow:[email protected]:5432/nklbcxow at java.sql.Drivermanager.getConnection(Drivermanager.java:689) at java.sql.Drivermanager.getConnection(Drivermanager.java:247) At Connectionfactory.getConnection(Connectionfactory.java:20) At productodao.registerTemp(Productodao.java:20) At Bdlearning.main(Bdlearning.java:25) C: Users Mathe Appdata Local Netbeans Cache 8.2 executor-snippets run.xml:53: Java returned: 1 CONSTRUCTION FAILURE (total time: 0 seconds)
Being that the site itself, is indicating to use the driver I’m already using :
I believe it is some format in the url that I’m not aware of, I tried some other ways, but no function.
Their website has a doc that gives an example of how to do in java, I copied the example and continued giving problem
So, friend, these are the information Elephant gives me. The url he gives me has its own format
– Matheus Barbosa
@Matheus maybe your Postgresql driver . jar is not configured correctly in your classpath.
– Wellington Costa
How do I see it ? As I said before, I used this same drive to connect to a local Postgressql.
– Matheus Barbosa
And in local Postgresql worked? You just changed the connection parameters?
– Wellington Costa
Yeah, it worked just by changing the parameters
– Matheus Barbosa