Advertisement
Guest User

Untitled

a guest
May 13th, 2017
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.52 KB | None | 0 0
  1. package jdbc;
  2.  
  3.  
  4.  
  5. import java.sql.Connection;
  6.  
  7. import java.sql.DriverManager;
  8.  
  9. import java.sql.SQLException;
  10.  
  11.  
  12.  
  13. public class ConnectionFactory {
  14.  
  15.    
  16.  
  17.     public Connection getConnection(){
  18.  
  19.         System.out.println("Conectando ao banco");
  20.  
  21.         try{
  22.  
  23.              Class.forName("com.mysql.jdbc.Driver").newInstance();
  24.  
  25.             Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/teste", "root", "julianna");
  26.  
  27.             return con;
  28.  
  29.         }catch(SQLException e){
  30.  
  31.             throw new RuntimeException(e);
  32.  
  33.         }
  34.  
  35.     }
  36.  
  37.    
  38.  
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement