Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.sql.*;
- public class Conexion {
- private Connection con;// Establecer la conexión
- private Statement sen; // Ejecutar consultas
- private ResultSet rs; // Recorrer los resultados (Tabla)
- public Conexion(String server, String bd, String user, String pass) throws SQLException{
- String protocolo = "jdbc:mysql://";
- String lineaUser = "user="+user;
- String lineaPass = "password="+pass;
- String url = protocolo +
- server + "/" +
- bd + "?" +
- lineaUser + "&" +
- lineaPass;
- System.out.println(url);
- Class.forName("com.mysql.jdbc.Driver");
- con = DriverManager.getConnection(url);
- }
- /*
- consultas actualizan los datos --> delete, insert, update
- ver datos --> select
- */
- // insert, delete, update
- public void ejecutar(String query) throws SQLException{
- sen = con.createStatement();
- sen.executeUpdate(query);
- desconectar();
- }
- public ResultSet ejecutarSelect(String query) throws SQLException{
- sen = con.createStatement();
- rs = sen.executeQuery(query);
- return rs;
- }
- public void desconectar() throws SQLException{
- sen.close();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement