Guest User

Untitled

a guest
Oct 19th, 2018
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.74 KB | None | 0 0
  1. package mx.hashCode.TimerError;
  2.  
  3. import java.sql.Connection;
  4. import java.sql.DriverManager;
  5. import java.sql.ResultSet;
  6. import java.sql.SQLException;
  7. import java.sql.Statement;
  8. import java.util.TimerTask;
  9. import java.util.logging.Level;
  10. import java.util.logging.Logger;
  11.  
  12. public class TimerSQL extends TimerTask {
  13. static private final Logger LOGGER = Logger.getLogger("mx.hashCode.TimerError.TimerSQL");
  14.  
  15. public Connection crearConexion() throws SQLException, ClassNotFoundException {
  16. Class.forName("com.mysql.cj.jdbc.Driver");
  17. String usuario = "archivista";
  18. String passwd = "123456789";
  19.  
  20. Connection cx = DriverManager.getConnection ("jdbc:mysql://127.0.0.1:3306/"+ "?useSSL=false&" + "user="+ usuario + "&" + "password=" + passwd + "");
  21.  
  22. return cx;
  23. }
  24.  
  25. @Override
  26. public void run() {
  27. try {
  28. String sql = "SELECT * FROM pruebas.juegos;";
  29.  
  30. try(Connection cx = this.crearConexion(); Statement consulta = cx.createStatement()) {
  31. ResultSet data = consulta.executeQuery(sql);
  32.  
  33. LOGGER.log(Level.INFO, "Presentaremos los datos");
  34. System.out.println("");
  35. while(data.next() == true) {
  36. System.out.print(data.getString("nombre") + " ");
  37. System.out.println(data.getString("consola"));
  38. }
  39. System.out.println("");
  40. data.close();
  41. }
  42.  
  43. } catch (SQLException | ClassNotFoundException e) {
  44. LOGGER.log(Level.SEVERE, "OCURRIO UN ERROR DE ACCESO A DB!!!");
  45. LOGGER.log(Level.SEVERE, "Pero el ciclo deberia repetirse sin problema");
  46. //LOGGER.log(Level.SEVERE, null, e);
  47. }
  48. }
  49.  
  50. }
Add Comment
Please, Sign In to add comment