Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.SQLException;
- /*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
- /**
- *
- * @author José
- */
- public class DataBaseConection {
- private static final String DATABASE = "Ifes";
- private static final String IP = "127.0.0.1";
- private static final String STR_CON = "jdbc:postgresql://"+ IP +":5432/"+DATABASE;
- private static final String USER = "postgres";
- private static final String PASSWORD = "379422";
- private Connection conn;
- public Connection conectar(){
- try{
- this.conn = DriverManager.getConnection(STR_CON, USER, PASSWORD);
- System.out.printf("conectado com sucesso...\n");
- return this.conn;
- }catch (SQLException e){
- System.out.printf( e.getMessage());
- return this.conn;
- }
- }
- public int desconectar (Connection c){
- try{
- c.close();
- System.out.printf("Desconectado com sucesso");
- return 0;
- } catch (SQLException e){
- return 1;
- }
- }
- }
Add Comment
Please, Sign In to add comment