Advertisement
Guest User

Untitled

a guest
Apr 12th, 2016
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1. package ConexionDB;
  2.  
  3. import java.sql.Connection;
  4. import java.sql.DriverManager;
  5. import java.sql.SQLException;
  6. import javax.swing.JOptionPane;
  7.  
  8. /**
  9. *
  10. * @author Kevin Arnold
  11. */
  12. public class ConexionDB {
  13.  
  14. public static Connection GetConnection()
  15. {
  16. Connection conexion=null;
  17.  
  18. try
  19. {
  20. Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
  21. String url = "jdbc:sqlserver://localhost;databaseName=DBVentas;user=sa;password=sa;";
  22. conexion= DriverManager.getConnection(url);
  23. }
  24. catch(ClassNotFoundException ex)
  25. {
  26. JOptionPane.showMessageDialog(null, ex, "Error1 en la Conexión con la BD "+ex.getMessage(), JOptionPane.ERROR_MESSAGE);
  27. conexion=null;
  28. }
  29. catch(SQLException ex)
  30. {
  31. JOptionPane.showMessageDialog(null, ex, "Error2 en la Conexión con la BD "+ex.getMessage(), JOptionPane.ERROR_MESSAGE);
  32. conexion=null;
  33. }
  34. catch(Exception ex)
  35. {
  36. JOptionPane.showMessageDialog(null, ex, "Error3 en la Conexión con la BD "+ex.getMessage(), JOptionPane.ERROR_MESSAGE);
  37. conexion=null;
  38. }
  39. finally
  40. {
  41. return conexion;
  42. }
  43. }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement