Estou tentando me conectar a um banco de dados feito pelo MS Access usando Java, mas não consigo. Estou usando ODBC e estou recebendo esta exceção:
java.sql.SQLException: [Microsoft] [ODBC Driver Manager] O DSN especificado contém uma incompatibilidade de arquitetura entre o driver e o aplicativo
Meu 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);
}
}
}