Advertisement
Guest User

Mysql Basic Connection

a guest
Aug 19th, 2016
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.30 KB | None | 0 0
  1. /*
  2.  * To change this license header, choose License Headers in Project Properties.
  3.  * To change this template file, choose Tools | Templates
  4.  * and open the template in the editor.
  5.  */
  6. package BasicMysql;
  7.  
  8. import java.sql.*;
  9. import java.util.logging.Level;
  10. import java.util.logging.Logger;
  11. /**
  12.  *
  13.  * @author jostx
  14.  */
  15. public class BasicMysql {
  16.  
  17.     /**
  18.      * @param args the command line arguments
  19.      */
  20.     public static void main(String[] args) {
  21.         // TODO code application logic here
  22.         String _Host = "127.0.0.1"; // HOST
  23.         String _User = "root"; // User
  24.         String _Pass = "251195"; // Pass
  25.         String _DB = "system_db"; // Database      
  26.        
  27.         Connection _DBConnect = null;
  28.  
  29.  
  30.         try {
  31.             Class.forName("com.mysql.jdbc.Driver");
  32.         } catch (ClassNotFoundException e) {
  33.             System.out.println("[MYSQL][ERROR] MySQL JDBC Driver no encontrado.");
  34.             return;
  35.         }
  36.        
  37.         try {
  38.             _DBConnect = DriverManager.getConnection("jdbc:mysql://"+_Host+":3306/"+_DB+"",_User, _Pass);
  39.         } catch (SQLException e) {
  40.             System.out.println("[MYSQL][ERROR] "+ "["+e.getErrorCode()+"]: " + e.getMessage());
  41.         }
  42.        
  43.         System.out.print(_DBConnect);
  44.        
  45.     }
  46.    
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement