- package com.connection;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import java.sql.Statement;
- public class SingleConnection {
- private static String url = "jdbc:mysql://localhost:3306/usuariosDb";
- private static String password = "";
- private static String user = "root";
- private static Connection connection;
- public static Connection getConnection() {
- if (connection == null) {
- try {
- connection = DriverManager.getConnection(url, user, password);
- connection.setAutoCommit(false);
- } catch (SQLException ex) {
- ex.printStackTrace();
- }
- }
- return connection;
- }
- public static void closeConnection() {
- if (connection != null) {
- try {
- connection.close();
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- }
- public static void closeStatement(Statement statement) {
- if (statement != null) {
- try {
- statement.close();
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- }
- public static void closeResultSet(ResultSet resultSet) {
- if (resultSet != null) {
- try {
- resultSet.close();
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- }
- }
[text] db
Viewer
*** This page was generated with the meta tag "noindex, nofollow". This happened because you selected this option before saving or the system detected it as spam. This means that this page will never get into the search engines and the search bot will not crawl it. There is nothing to worry about, you can still share it with anyone.
Editor
You can edit this paste and save as new: