SHARE
TWEET

Untitled

a guest Oct 18th, 2019 94 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.sql.Connection;
  2. import java.sql.DriverManager;
  3. import java.sql.ResultSet;
  4. import java.sql.SQLException;
  5. import java.sql.Statement;
  6.  
  7. public class Conexion {
  8.     private Statement sen;
  9.     private final Connection con;
  10.  
  11.     public Conexion(String bd) throws ClassNotFoundException, SQLException {
  12.         String url = "jdbc:mysql://localhost/" + bd + "?user=root&password=";
  13.         System.out.println(url);
  14.         Class.forName("com.mysql.jdbc.Driver");
  15.         con = DriverManager.getConnection(url);
  16.     }
  17.  
  18.     public ResultSet ejecutar(String query) throws SQLException {
  19.         System.out.println(query);
  20.         sen = con.createStatement();
  21.  
  22.         if (
  23.             query.toLowerCase().startsWith("insert") ||
  24.             query.toLowerCase().startsWith("update") ||
  25.             query.toLowerCase().startsWith("delete")
  26.         ) {
  27.             sen.executeUpdate(query);
  28.             close();
  29.             return null;
  30.         }
  31.            
  32.         return sen.executeQuery(query);
  33.     }
  34.  
  35.     public void close() throws SQLException {
  36.         sen.close();
  37.     }
  38. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top