Guest User

Untitled

a guest
Sep 18th, 2018
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.20 KB | None | 0 0
  1.  
  2. import java.sql.Connection;
  3. import java.sql.DriverManager;
  4. import java.sql.SQLException;
  5. /*
  6.  * To change this template, choose Tools | Templates
  7.  * and open the template in the editor.
  8.  */
  9.  
  10. /**
  11.  *
  12.  * @author José
  13.  */
  14. public class DataBaseConection {
  15.     private static final String DATABASE = "Ifes";
  16.     private static final String IP = "127.0.0.1";
  17.     private static final String STR_CON = "jdbc:postgresql://"+ IP +":5432/"+DATABASE;
  18.     private static final String USER = "postgres";
  19.     private static final String PASSWORD = "379422";
  20.     private Connection conn;
  21.    
  22.     public Connection conectar(){
  23.         try{
  24.             this.conn = DriverManager.getConnection(STR_CON, USER, PASSWORD);
  25.             System.out.printf("conectado com sucesso...\n");
  26.             return this.conn;
  27.         }catch (SQLException e){
  28.             System.out.printf( e.getMessage());
  29.             return this.conn;
  30.            
  31.         }
  32.     }
  33.    
  34.     public int desconectar (Connection c){
  35.         try{
  36.             c.close();
  37.             System.out.printf("Desconectado com sucesso");
  38.             return 0;
  39.         } catch (SQLException e){
  40.             return 1;
  41.        
  42.         }
  43.     }
  44. }
Add Comment
Please, Sign In to add comment