Advertisement
Jonas_3k

/*- Conexão DB Mysql:JDBC -*/

Feb 2nd, 2019
215
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.81 KB | None | 0 0
  1. package conectabanco;
  2.  
  3. import java.sql.Connection;
  4. import java.sql.DriverManager;
  5. import java.sql.SQLException;
  6.  
  7. public class ConectaBanco {
  8.  
  9.     private static final String DRIVER = "com.mysql.jdbc.Driver";
  10.     private static final String URL = "jdbc:mysql://localhost:3306/catalogoloja";
  11.     private static final String USUARIO = "root";
  12.     private static final String SENHA = "123";
  13.    
  14.     public static void main(String[] args) throws ClassNotFoundException {
  15.         //Carrega o Driver
  16.         Class.forName(DRIVER);
  17.         try{
  18.             //Cria a conexão
  19.             Connection conexao =  DriverManager.getConnection(URL, USUARIO,SENHA);
  20.             System.out.println("Conectado");
  21.         }catch(SQLException exp){
  22.             System.err.println("Erro "+exp);
  23.         }        
  24.     }
  25.    
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement