|
|
@ -1,5 +1,40 @@ |
|
|
|
package com.jorpelu; |
|
|
|
|
|
|
|
public class ConectorBD { |
|
|
|
import java.sql.*; |
|
|
|
|
|
|
|
|
|
|
|
public class ConectorBD { |
|
|
|
|
|
|
|
private static String USER = "root"; |
|
|
|
private static String URL ="jdbc:odbc:MariaDB"; |
|
|
|
|
|
|
|
|
|
|
|
public static void main(String[] args) { |
|
|
|
Connection conexion; |
|
|
|
Statement statement; |
|
|
|
ResultSet resultado; |
|
|
|
|
|
|
|
System.out.println("----------Inicio del programa----------"); |
|
|
|
|
|
|
|
try { |
|
|
|
String query = "SELECT ID, NOBRE, APELLIDOS FROM TEST"; |
|
|
|
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); |
|
|
|
conexion = DriverManager.getConnection(URL, USER, ""); |
|
|
|
statement = conexion.createStatement(); |
|
|
|
String query1 = "CREATE TABLE IF NOT EXISTS TEST (ID INTEGER() NOT NULL AUTOINCREMENT, NOMBRE VARCHAR(50) NOT NULL, APELLIDOS VARCHAR(50) NOT NULL) "; |
|
|
|
statement.execute(query1); |
|
|
|
resultado = statement.executeQuery(query); |
|
|
|
while(resultado.next()) { |
|
|
|
int id = resultado.getInt("ID"); |
|
|
|
String name = resultado.getString("NOMBRE"); |
|
|
|
String edad = resultado.getString("APELLIDOS"); |
|
|
|
System.out.println(id + " " + name + " " + edad + " " ); |
|
|
|
} |
|
|
|
conexion.close(); |
|
|
|
} catch (Exception e) { |
|
|
|
System.out.println( "No se pudo cargar el puente JDBC-ODBC." ); |
|
|
|
e.printStackTrace(); |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
} |