Advertisement
Guest User

Untitled

a guest
Jun 28th, 2016
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.78 KB | None | 0 0
  1. import java.sql.*;
  2.  
  3. public class Conexao {
  4.  
  5. public static Connection abrirConexao() {
  6. String driver = "org.postgresql.Driver";
  7. String user = "postgres";
  8. String senha = "ifb";
  9. String url = "jdbc:postgresql://127.0.0.1:5432/loja";
  10. Connection con = null;
  11. try {
  12. Class.forName(driver);
  13. con = (Connection) DriverManager.getConnection(url, user, senha);
  14. } catch (ClassNotFoundException ex) {
  15. System.err.print(ex.getMessage());
  16. } catch (SQLException e) {
  17. System.err.print(e.getMessage());
  18. }
  19. return con;
  20. }
  21. public static void fecharConexao(Connection con){
  22. try{
  23. con.close();
  24. }catch(SQLException e){
  25.  
  26. }
  27. }
  28. }
  29. mexer no que ?
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement