Advertisement
Guest User

Untitled

a guest
May 20th, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.61 KB | None | 0 0
  1. import java.sql.*;
  2.  
  3. public class Conexao {
  4.     static String status = "";
  5.     public static Connection getConnection(){
  6.             Connection con = null;
  7.             try {
  8.      Class.forName("com.mysql.jdbc.Driver").newInstance();
  9.      String url = "jdbc:mysql://127.0.0.1/loja?user=root&password=root";  
  10.      con = DriverManager.getConnection(url);   
  11.     status = "Conexão Aberta";//muda o status para conexão aberta.           
  12.     } catch (ClassNotFoundException e) {               
  13.         status = e.getMessage();
  14.     } catch (SQLException e) {                 
  15.         status = e.getMessage();
  16.     } catch (Exception e){
  17.     status = e.getMessage();
  18.     }
  19.     return con;
  20.     }
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement