Advertisement
Khristianx

Untitled

Jul 18th, 2016
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.02 KB | None | 0 0
  1. public class MySQL_Test {
  2.  
  3.  
  4.     public static void main(String[] args) {
  5.        MySQL db = new MySQL();
  6.         try {
  7.             db.MySQLConnection("root","","");
  8.         } catch (Exception ex) {
  9.             Logger.getLogger(MySQL_Test.class.getName()).log(Level.SEVERE, null, ex);
  10.         }
  11.     }
  12.    
  13. }
  14. public class MySQL {
  15.  
  16.     private static Connection Conexion;
  17.  
  18.  
  19.     public void MySQLConnection(String user, String pass, String db_name) throws Exception {
  20.         try {
  21.             Class.forName("com.mysql.jdbc.Driver");
  22.             Conexion = DriverManager.getConnection("jdbc:mysql://localhost:3306/" + db_name, user, pass);
  23.             JOptionPane.showMessageDialog(null, "Se ha iniciado la conexión con el servidor de forma exitosa");
  24.         } catch (ClassNotFoundException ex) {
  25.             Logger.getLogger(MySQL.class.getName()).log(Level.SEVERE, null, ex);
  26.         } catch (SQLException ex) {
  27.             Logger.getLogger(MySQL.class.getName()).log(Level.SEVERE, null, ex);
  28.         }
  29.     }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement