Advertisement
Guest User

Untitled

a guest
Jun 21st, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 KB | None | 0 0
  1. package Modelo;
  2. import java.sql.Connection;
  3. import java.sql.DriverManager;
  4. import java.sql.SQLException;
  5. import java.sql.Statement;
  6.  
  7. public class Conectar {
  8. private Connection conn;
  9.  
  10. private String registrar(){
  11. try{
  12. Class.forName("com.mysql.jdbc.Driver");
  13. return "Exito";
  14. }catch(ClassNotFoundException e){
  15. return "no registrado";
  16. }
  17. }
  18.  
  19. private String obtenerConexion(){
  20. try{
  21. conn=DriverManager.getConnection("jdbc:mysql://localhost/bodyfit","root","root");
  22. return "Exito";
  23. }catch (SQLException e){
  24. return "no conectado";
  25. }
  26. }
  27.  
  28. public Statement crearSentencia(){
  29. try{
  30. Statement s = conn.createStatement();
  31. return s;
  32. }catch(SQLException e){
  33. return null;
  34. }
  35. }
  36.  
  37. public Conectar() {
  38. registrar();
  39. obtenerConexion();
  40. }
  41.  
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement