Estoy tratando de conectarme a una base de datos creada por MS Access usando Java, pero parece que no puedo administrar. Estoy usando ODBC y obtengo esta excepción:
java.sql.SQLException: [Microsoft] [ODBC Driver Manager] El DSN especificado contiene una discrepancia de arquitectura entre el controlador y la aplicación
Mi Java:
package javaapplication2;
import java.sql.Statement;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
/**
*
* @author Owner
*/
public class JavaApplication2 {
/**
* @param args the command line arguments
*
*/
public static void main(String[] args) {
// TODO code application logic here
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String sourceURL = new String("jdbc:odbc:myDatabase");
System.out.println(sourceURL);
Connection dbConnection = DriverManager.getConnection(sourceURL,"admin","");
Statement myStmt = dbConnection.createStatement();
String query = "INSERT INTO People(ID, Name, Surname, Age, Contact, Location, Course) VALUES"
+ " (1007, 'Elroy', 'Smith', '33', 21366688, 'Somewhere', 'somecourse')";
myStmt.executeUpdate(query);
ResultSet results = myStmt.executeQuery("SELECT * FROM People");
while(results.next())
{
System.out.print(results.getString(1));
System.out.print(results.getString(2));
System.out.print(results.getString(3));
System.out.println(results.getString(4));
}
results.close();
}
catch(ClassNotFoundException cnfe)
{
System.out.println(cnfe);
}
catch(SQLException sqle)
{
System.out.println(sqle);
}
}
}