Guest User

Untitled

a guest
Apr 11th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.09 KB | None | 0 0
  1. package com.util;
  2.  
  3. import java.sql.DriverManager;
  4. import java.sql.ResultSet;
  5. import java.sql.Connection;
  6.  
  7. public class Conexion {
  8. private Connection conexion;
  9. static String bd="Juego";
  10. static String user="root";
  11. static String password="";
  12. static String server="jdbc:mysql://localhost/"+bd;
  13.  
  14. public void establecerConexion(){
  15. try{
  16. Class.forName("com.mysql.jdbc.Driver");
  17. conexion = DriverManager.getConnection(server,user,password);
  18. }
  19. catch(Exception e){
  20. System.out.println("Imposible realizar conexion con la BD");
  21. e.printStackTrace();
  22. }
  23. }
  24.  
  25. public Connection getConexion(){
  26. return conexion;
  27. }
  28.  
  29. public void cerrar(ResultSet rs){
  30. if(rs !=null){
  31. try{
  32. rs.close();
  33. }
  34. catch(Exception e){
  35. System.out.print("No es posible cerrar la Conexion");
  36. }
  37. }
  38. }
  39.  
  40. public void cerrar(java.sql.Statement stmt){
  41. if(stmt !=null){
  42. try{
  43. stmt.close();
  44. }
  45. catch(Exception e){}
  46. }
  47. }
  48.  
  49. public void cerrarConexion(){
  50. if(conexion !=null){
  51.  
  52. try{
  53. conexion.close();
  54. }
  55. catch(Exception e){}
  56. }
  57. }
  58.  
  59. }
Add Comment
Please, Sign In to add comment