Advertisement
Guest User

Untitled

a guest
Jul 23rd, 2016
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.84 KB | None | 0 0
  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=JAVA;integratedSecurity=true;";
  8.  
  9. try {
  10. Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver").newInstance();
  11. Connection conn = DriverManager.getConnection(connectionUrl);
  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("erro ao conectar com o banco de dados: " + e);
  22. }
  23. }
  24. }
  25.  
  26. String connectionUrl= jdbc://sqlserver:Joy\sqlexpress;databaseName=JAVA;integratedSecurity=true;"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement