Advertisement
Guest User

Untitled

a guest
Dec 10th, 2016
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.14 KB | None | 0 0
  1. import java.sql.Connection;
  2. import java.sql.DriverManager;
  3. import java.sql.ResultSet;
  4. import java.sql.SQLException;
  5. import java.util.logging.Level;
  6. import java.util.logging.Logger;
  7.  
  8. public class Conexion {
  9.  
  10. Connection con;
  11.  
  12. public Conexion(String user, String password, String host) {
  13. try {
  14. Class.forName("com.mysql.jdbc.Driver");
  15. con = DriverManager.getConnection("jdbc:mysql://" + host + "/mysql", user, password);
  16. } catch (ClassNotFoundException ex) {
  17. Logger.getLogger(Conexion.class.getName()).log(Level.SEVERE, null, ex);
  18. } catch (SQLException ex) {
  19. Logger.getLogger(Conexion.class.getName()).log(Level.SEVERE, null, ex);
  20. }
  21. }
  22.  
  23. public boolean existeDB(String db) {
  24. try {
  25. ResultSet rs = con.createStatement().executeQuery("show databases");
  26. while (rs.next()) {
  27. if (rs.getString(1).equals(db)) {
  28. return true;
  29. }
  30. }
  31. } catch (SQLException ex) {
  32. Logger.getLogger(Conexion.class.getName()).log(Level.SEVERE, null, ex);
  33. }
  34. return false;
  35. }
  36.  
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement