jivagomr

Classe ConnBD

Apr 4th, 2017 (edited)
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.09 KB | None | 0 0
  1. /*
  2.  * To change this license header, choose License Headers in Project Properties.
  3.  * To change this template file, choose Tools | Templates
  4.  * and open the template in the editor.
  5.  */
  6. package util;
  7.  
  8. import java.sql.Connection;
  9. import java.sql.DriverManager;
  10. import java.sql.ResultSet;
  11. import java.sql.SQLException;
  12. import java.sql.Statement;
  13. import java.util.Scanner;
  14.  
  15. /**
  16.  *
  17.  * @author Jivago
  18.  */
  19. public class ConnBD {
  20.  
  21.     public static Connection getConnection() {
  22.  
  23.         String strCon
  24.                 = "jdbc:mysql://localhost:3306/aulas";
  25.  
  26.         try {
  27.             Class.forName("com.mysql.jdbc.Driver");
  28.             Connection con;
  29.             con = DriverManager
  30.                     .getConnection(strCon, "root", "");
  31.  
  32.  
  33.             return con;
  34.  
  35.         } catch (SQLException ex) {
  36.             System.out.println("Erro conectando"
  37.                     + "no banco de dados"
  38.                     + ex.getMessage());
  39.         } catch (ClassNotFoundException ex) {
  40.             System.out.println(ex.getMessage());
  41.         }
  42.        
  43.         return null;
  44.  
  45.     }
  46.  
  47. }
Add Comment
Please, Sign In to add comment