Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package servicios;
- import java.sql.*;
- public class Conexion {
- private static Connection cnx = null;
- public static Connection obtener() throws SQLException, ClassNotFoundException {
- if (cnx == null) {
- try {
- Class.forName("com.mysql.jdbc.Driver");
- cnx = DriverManager.getConnection("jdbc:mysql://localhost/java_mysql", "root", "");
- } catch (SQLException ex) {
- throw new SQLException(ex);
- } catch (ClassNotFoundException ex) {
- throw new ClassCastException(ex.getMessage());
- }
- }
- return cnx;
- }
- public static void cerrar() throws SQLException {
- if (cnx != null) {
- cnx.close();
- }
- }
- }
Add Comment
Please, Sign In to add comment