Guest User

Untitled

a guest
Feb 19th, 2018
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.64 KB | None | 0 0
  1. package servicios;
  2. import java.sql.*;
  3.  
  4. public class Conexion {
  5. private static Connection cnx = null;
  6. public static Connection obtener() throws SQLException, ClassNotFoundException {
  7. if (cnx == null) {
  8. try {
  9. Class.forName("com.mysql.jdbc.Driver");
  10. cnx = DriverManager.getConnection("jdbc:mysql://localhost/java_mysql", "root", "");
  11. } catch (SQLException ex) {
  12. throw new SQLException(ex);
  13. } catch (ClassNotFoundException ex) {
  14. throw new ClassCastException(ex.getMessage());
  15. }
  16. }
  17. return cnx;
  18. }
  19.  
  20. public static void cerrar() throws SQLException {
  21. if (cnx != null) {
  22. cnx.close();
  23. }
  24. }
  25. }
Add Comment
Please, Sign In to add comment