Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package odbc;
- import com.mysql.jdbc.Connection;
- import java.sql.DriverManager;
- import java.sql.SQLException;
- /**
- *
- * @author Estudiante
- */
- public class ODBC {
- /**
- * @param args the command line arguments
- */
- private static Connection conexion;
- private static String bd="museo";
- private static String user="root";
- private static String password="1234";
- private static String host="localhost";
- private static String server="jdbc:mysql://"+host+"/"+bd;
- public static void main(String[] args) {
- //conectar
- try {
- Class.forName("com.mysql.jdbc.Driver");
- conexion = (Connection) DriverManager.getConnection(server, user, password);
- System.out.println("Conexión a base de datos " + server + " ... OK");
- } catch (ClassNotFoundException ex) {
- System.out.println("Error cargando el Driver MySQL JDBC ... FAIL");
- } catch (SQLException ex) {
- System.out.println("Imposible realizar conexion con "+server+" ... FAIL");
- }
- //Espacio para realizar consultas, agregar registros, eliminar registros, etc...
- //desconectar
- try {
- conexion.close();
- System.out.println("Cerrar conexion con "+server+" ... OK");
- } catch (SQLException ex) {
- System.out.println("Imposible cerrar conexion ... FAIL");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement