Advertisement
Guest User

Untitled

a guest
Aug 8th, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.44 KB | None | 0 0
  1. /*
  2.  * To change this template, choose Tools | Templates
  3.  * and open the template in the editor.
  4.  */
  5.  
  6. package LaLiga;
  7.  
  8. import com.mysql.jdbc.Connection;
  9. import java.sql.DriverManager;
  10. import java.sql.ResultSet;
  11.  
  12. /**
  13.  *
  14.  * @author Lucaso1989
  15.  */
  16. public class DataBaseConnection {
  17.  
  18.     private Connection DataBaseConnection;
  19.  
  20.     public DataBaseConnection() {
  21.  
  22.     }
  23.  
  24.     public void init() {
  25.  
  26.         try {
  27.             Class.forName("com.mysql.jdbc.Driver");
  28.             DataBaseConnection = (Connection) DriverManager.getConnection(
  29.                 "jdbc:mysql://db4free.net/laliga","lukkas", "b1a8r9c9a"
  30.                 );
  31.         }
  32.         catch(Exception e){
  33.             System.out.println("Failed to get connection");
  34.             e.printStackTrace();
  35.         }
  36.  
  37.     }
  38.    
  39.     public Connection getConnection(){
  40.         return DataBaseConnection;
  41.     }
  42.  
  43.  
  44.     public void close(ResultSet rs){
  45.  
  46.         if(rs !=null){
  47.             try{
  48.                rs.close();
  49.             }
  50.             catch(Exception e){}
  51.         }
  52.     }
  53.  
  54.      public void close(java.sql.Statement stmt){
  55.  
  56.         if(stmt !=null){
  57.             try{
  58.                stmt.close();
  59.             }
  60.             catch(Exception e){}
  61.         }
  62.     }
  63.  
  64.      public void destroy(){
  65.  
  66.         if(DataBaseConnection !=null){
  67.             try{
  68.                DataBaseConnection.close();
  69.             }
  70.             catch(Exception e){}
  71.         }
  72.     }
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement