Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import java.util.logging.Level;
- import java.util.logging.Logger;
- public class Conexion {
- Connection con;
- public Conexion(String user, String password, String host) {
- try {
- Class.forName("com.mysql.jdbc.Driver");
- con = DriverManager.getConnection("jdbc:mysql://" + host + "/mysql", user, password);
- } catch (ClassNotFoundException ex) {
- Logger.getLogger(Conexion.class.getName()).log(Level.SEVERE, null, ex);
- } catch (SQLException ex) {
- Logger.getLogger(Conexion.class.getName()).log(Level.SEVERE, null, ex);
- }
- }
- public boolean existeDB(String db) {
- try {
- ResultSet rs = con.createStatement().executeQuery("show databases");
- while (rs.next()) {
- if (rs.getString(1).equals(db)) {
- return true;
- }
- }
- } catch (SQLException ex) {
- Logger.getLogger(Conexion.class.getName()).log(Level.SEVERE, null, ex);
- }
- return false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement