Advertisement
Guest User

Untitled

a guest
May 3rd, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1.  
  2. package odbc;
  3.  
  4. import com.mysql.jdbc.Connection;
  5. import java.sql.DriverManager;
  6. import java.sql.SQLException;
  7.  
  8. /**
  9. *
  10. * @author Estudiante
  11. */
  12. public class ODBC {
  13.  
  14. /**
  15. * @param args the command line arguments
  16. */
  17. private static Connection conexion;
  18. private static String bd="museo";
  19. private static String user="root";
  20. private static String password="1234";
  21. private static String host="localhost";
  22. private static String server="jdbc:mysql://"+host+"/"+bd;
  23. public static void main(String[] args) {
  24. //conectar
  25. try {
  26. Class.forName("com.mysql.jdbc.Driver");
  27. conexion = (Connection) DriverManager.getConnection(server, user, password);
  28. System.out.println("Conexión a base de datos " + server + " ... OK");
  29. } catch (ClassNotFoundException ex) {
  30. System.out.println("Error cargando el Driver MySQL JDBC ... FAIL");
  31. } catch (SQLException ex) {
  32. System.out.println("Imposible realizar conexion con "+server+" ... FAIL");
  33. }
  34.  
  35. //Espacio para realizar consultas, agregar registros, eliminar registros, etc...
  36. //desconectar
  37. try {
  38. conexion.close();
  39. System.out.println("Cerrar conexion con "+server+" ... OK");
  40. } catch (SQLException ex) {
  41. System.out.println("Imposible cerrar conexion ... FAIL");
  42.  
  43. }
  44. }
  45.  
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement