Guest User

[TRABALHO] - Código 01: Tutorial

a guest
Sep 29th, 2017
30
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.68 KB | None | 0 0
  1. package br.edu.tutorial.trabalho;
  2.  
  3. import java.sql.Connection;
  4.  
  5. public class ConexaoUtil {
  6.  
  7.     private static ConexaoUtil conexaoUtil;
  8.    
  9.     public static ConexaoUtil getInstance() {
  10.         if (conexaoUtil == null) {
  11.             conexaoUtil = new ConexaoUtil();
  12.         }
  13.         return ConexaoUtil;
  14.     }
  15.     public Connection getConnection() {
  16.         Class.forName("com.mysql.jdbc.Driver");
  17.        
  18.         return DriverManager.getConnection("jdbc:mysql://localhost:3306/nome_do_banco","root","root"); // (servidor que vai rodar o mysql, usuario, senha).
  19.     }
  20.    
  21.     public static void main(String[]args)   {
  22.         try {
  23.             System.out.println(getInstanc().getConnection());
  24.         }   catch (Exception e) {
  25.             e.printStackTrace();
  26.         }
  27.     }
  28. }
Add Comment
Please, Sign In to add comment