Guest User

Untitled

a guest
Mar 12th, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.80 KB | None | 0 0
  1. import java.sql.*;
  2. public class BancoTeste {
  3.  
  4.     public static void main(String args[]) {
  5.    
  6.         Connection conn = null;
  7.        
  8.  
  9.         try {
  10.             Class.forName("com.mysql.jdbc.Driver");
  11.             conn = DriverManager.getConnection( "jdbc:mysql://localhost/test?user=root&password=default" );
  12.             Statement stm = conn.createStatement();  
  13.             System.out.println("Conectou");
  14.         } catch(ClassNotFoundException e) {
  15.             e.printStackTrace();
  16.         } catch(SQLException e) {  
  17.             e.printStackTrace();
  18.         } finally {
  19.             try {
  20.                 conn.close();
  21.             } catch(SQLException a) {
  22.                 System.out.println("Nao fechou conexão");
  23.                 a.printStackTrace();
  24.             }
  25.         }
  26.     }
  27. }
Add Comment
Please, Sign In to add comment