daily pastebin goal
88%
SHARE
TWEET

Conexão SQL Server JDBC - Java com Autenticação do SQL

angeliski Nov 6th, 2011 587 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.sql.*;
  2.  
  3. public class Main {
  4.   public static void main(String[] args) {
  5.     // string de conexão...usando Windows Authentication
  6.     String connectionUrl = "jdbc:sqlserver://localhost:1433;" +
  7.       "databaseName=estudos;";
  8.  
  9.     try {
  10.       Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver").newInstance();
  11.       Connection conn = DriverManager.getConnection(connectionUrl,"sa","1234");
  12.       System.out.println("Conexão obtida com sucesso.");
  13.     }
  14.     catch (SQLException ex) {
  15.       System.out.println("SQLException: " + ex.getMessage());
  16.       System.out.println("SQLState: " + ex.getSQLState());
  17.       System.out.println("VendorError: " + ex.getErrorCode());
  18.     }
  19.     catch (Exception e) {
  20.        
  21.       System.out.println("Problemas ao tentar conectar com o banco de dados: " + e);
  22.     }
  23.   }
  24. }
  25.  
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top