Jothar_Aleksander 17 de set. de 2019
Não consegui localizar o driver do PostgreSQL no seu código. Você precisa informar o Driver, o URL, a senha e o usuário. Creio que o driver do PostgreSQL seja org.postgresql.Driver.
allan_esig 17 de set. de 2019
fica dando erro no getconnection:
package br.com.farmacia.conexao;
import java.sql.Connection ;
import java.sql.DriverManager ;
import java.sql.SQLException ;
public class conexaoFactory {
private static final String DRIVER = “ org . postgresql . Driver ” ;
private static final String USUARIO = “ root ” ;
private static final String SENHA = “ 32022212 ” ;
private static final String URL = “ jdbc : postgresql : //localhost:5432/sistema”;
public static Connection conectar () throws SQLException {
Connection conexao = DriverManager .getConnection ( DRIVER ,USUARIO ,SENHA ,URL ) ;
return conexao ;
}
public static void main ( String [] args ) {
try {
Connection conexao = conexaoFactory . conectar ();
System . out . println ( “ Conectado com Sucesso ! ” );
} catch ( SQLException e ) {
e . printStackTrace ();
System . out . println ( “ Erro na conexão . ” );
}
}
}
Jothar_Aleksander 17 de set. de 2019
Use o Class.forName(Driver) para carregar o Driver. Exemplo:
public class ConectaBancoDeDados {
public static final String DRIVER = "org.postgresql.Driver" ;
public static final String URL = "jdbc:postgresql://localhost/"
+ "PetShop" ;
public static final String USUARIO = "jfsjr" ;
public static final String SENHA = "blitzkrieg" ;
public static Connection getConexao () throws SQLException {
try {
Class . forName ( DRIVER );
return DriverManager . getConnection ( URL , USUARIO , SENHA );
} catch ( ClassNotFoundException cnfe ){
throw new SQLDataException ( cnfe . getMessage ());
}
}
}
allan_esig 18 de set. de 2019
public class ConectaBancoDeDados { public static final String DRIVER = “org.postgresql.Driver”; public static final String URL = “jdbc:postgresql://localhost/” + “PetShop”; public static final String USUARIO = “jfsjr”; public static final String SENHA = “blitzkrieg”; public static Connection getConexao() throws SQLException{ try{ Class.forName(DRIVER); return DriverManager.getConnection(URL, USUARIO, SENHA); }catch(ClassNotFoundException cnfe){ throw new SQLDataException(cnfe.getMessage()); } } }
infelizmente ainda deu problema
allan_esig 18 de set. de 2019
package br.com.farmacia.conexao;
import java.sql.Connection ;
import java.sql.DriverManager ;
import java.sql.SQLDataException ;
import java.sql.SQLException ;
public class ConectaBancoDeDados {
public static final String DRIVER = “ org . postgresql . Driver ” ;
public static final String URL = “ jdbc : postgresql : //localhost:5432/”
+ “ sistema ” ;
public static final String USUARIO = “ root ” ;
public static final String SENHA = “ 32022212 ” ;
public static Connection getConexao () throws SQLException {
try {
Class . forName ( DRIVER );
return DriverManager . getConnection ( URL , USUARIO , SENHA );
} catch ( ClassNotFoundException cnfe ){
throw new SQLDataException ( cnfe . getMessage ());
}
}
}
Deixei a classe assim
staroski 18 de set. de 2019
O driver do postgres está no classpath de sua aplicação?
allan_esig 20 de set. de 2019
allan_esig 20 de set. de 2019
Dá esse erro :
// Compiled from Driver.java (version 1.8 : 52.0, super bit)
public class org . postgresql . Driver implements java . sql . Driver {
// Field descriptor #14 Lorg/postgresql/Driver;
private static org.postgresql.Driver registeredDriver;
// Field descriptor #16 Ljava/util/logging/Logger;
private static final java.util.logging.Logger PARENT_LOGGER;
// Field descriptor #16 Ljava/util/logging/Logger;
private static final java.util.logging.Logger LOGGER;
// Field descriptor #19 Lorg/postgresql/util/SharedTimer;
private static org.postgresql.util.SharedTimer sharedTimer;
// Field descriptor #21 Ljava/lang/String;
private static final java.lang.String DEFAULT_PORT = “5432”;
// Field descriptor #25 Ljava/util/Properties;
private java.util.Properties defaultProperties;
// Field descriptor #21 Ljava/lang/String;
private static java.lang.String loggerHandlerFile;