java.sql.SQLException: [Microsoft][ODBC Driver Manager] The specified DSN contains an architecture mismatch between the Driver and Application [duplicate]

StackOverflow https://stackoverflow.com/questions/16425063

  •  14-04-2022
  •  | 
  •  

Domanda

The below code:

public void insertNewStudent(int id, String pass, String fname, String lname, String   street, String city, String state, int Zip, String Email, double GPA) {
    try {
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    conn = DriverManager.getConnection("jdbc:odbc:RegistrationDB", "", "");
    String query = "INSERT INTO Students (ID, Password, FirstName, LastName, Street, City, State, Zip, EMail, GPA)" + "VALUES (?,?,?,?,?,?,?,?,?,?)";
    PreparedStatement ps = conn.prepareStatement(query);
    ps.setInt(1, id);
    ps.setString(2, pass);
    ps.setString(3, fname);
    ps.setString(4, lname);
    ps.setString(5, street);
    ps.setString(6, city);
    ps.setString(7, state);
    ps.setInt(8, Zip);
    ps.setString(9, Email);
    ps.setDouble(10, GPA);
    ps.executeUpdate();
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}

Throws the below exception:

java.sql.SQLException: [Microsoft][ODBC Driver Manager] The specified DSN contains an     architecture mismatch between the Driver and Application
    sun.jdbc.odbc.JdbcOdbc.createSQLException(JdbcOdbc.java:6956)
    sun.jdbc.odbc.JdbcOdbc.standardError(JdbcOdbc.java:7113)
    sun.jdbc.odbc.JdbcOdbc.SQLDriverConnect(JdbcOdbc.java:3072)
    sun.jdbc.odbc.JdbcOdbcConnection.initialize(JdbcOdbcConnection.java:323)
    sun.jdbc.odbc.JdbcOdbcDriver.connect(JdbcOdbcDriver.java:174)
    java.sql.DriverManager.getConnection(DriverManager.java:579)
    java.sql.DriverManager.getConnection(DriverManager.java:221)
    business.studentDB.insertNewStudent(studentDB.java:53)
    controller.registercontrol.doPost(registercontrol.java:47)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:641)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
    org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:393)

How is this caused and how can I solve it?

È stato utile?

Soluzione

So changing your exception handling uncovered your real problem, which seems to be:

The specified DSN contains an architecture mismatch between the Driver and Application

This basically tells that you have either 32-bit driver against 64-bit access or other way around. You need to find out which and use the correct one. More on this problem on this thread, for example.

Altri suggerimenti

Add a finally block

PreparedStatement ps = null; // declare outside the try block
try {
  // ...
} catch (Exception e) {
  // ...
} finally {
  try {
    if (ps != null) ps.close();
    if (conn != null) conn.close();
  } catch (SQLException e) {
    // ...
  }
}

Leaving the Connection open may not be committing the changes to the database. If the Connection is being shared and you can't close it commit() your changes explicitly.

ps.executeUpdate();
conn.commit();

EDIT: In light of the stack trace shared please make sure that your Java IDE, Microsoft Access and JVM or JDK are all of the same bit i.e. either 32 or 64 bit versions. But, yes adding the finally block is still recommended.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top