Advertisement
Guest User

Untitled

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