Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package cl.pokemonProject.bd;
- 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, ClassNotFoundException {
- 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);
- /*
- MysqlDataSource mysql = new MysqlDataSource();
- mysql.setServerName(server);
- mysql.setDatabaseName(bd);
- mysql.setUser(user);
- mysql.setPassword(pass);
- con = mysql.getConnection();
- */
- }
- /*
- Consultas actualizan los datos --> delete,insert,update
- ver datos--> select;
- */
- /*Metodo sirve para insert,update,delete*/
- public void ejecutar(String query) throws SQLException {
- sen = con.createStatement();
- sen.executeUpdate(query);
- sen.close();
- }
- 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