Guest User

Untitled

a guest
Nov 21st, 2018
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.22 KB | None | 0 0
  1. package dbtienda;
  2. import java.sql.SQLException;
  3. import java.sql.DriverManager;
  4. import java.sql.*;
  5.  
  6.  
  7. public class DBtienda {
  8.  
  9. /**
  10. * @param args the command line arguments
  11. */
  12.  
  13. public static Connection getConnection() {
  14. Connection connection = null;
  15. String dbName = "tienda";
  16. String user = "conexion";
  17. String pass = "3312";
  18. try {
  19. //Class.forName("com.microsoft.sqlserver.jbdc.SQLServerDriver");
  20. //String connectionDB = "jbdc:sqlserver://localhost\SQLEXPRESS;database="
  21. String connectionDB = "jbdc:sqlserver://LAPTOP-2V4ND64M\SQLEXPRESS;database="
  22. //+ dbName + ";user = " + user + ";password = " + pass + ";";
  23. + dbName + ";integratedSecurity=true;";
  24. connection = DriverManager.getConnection(connectionDB);
  25. }
  26.  
  27. /*catch(Exception e) {
  28. System.out.println("Error: " + e.getMessage());
  29. }*/
  30. catch(SQLException e) {
  31. System.out.println("Error: " + e.getMessage());
  32. }
  33. catch(Exception e) {
  34. System.out.println("Error: " + e.getMessage());
  35. }
  36.  
  37. return connection;
  38. }
  39.  
  40. public static void main(String[] args) {
  41. if(DBtienda.getConnection() != null)
  42. System.out.println("Conexión exitosa!");
  43. }
  44.  
  45. }
Add Comment
Please, Sign In to add comment