Microsoft Access and Java JDBC-ODBC Error

Posted by user1638362 on Stack Overflow See other posts from Stack Overflow or by user1638362
Published on 2012-12-08T09:44:57Z Indexed on 2012/12/08 11:06 UTC
Read the original article Hit count: 317

Filed under:
|
|
|

Trying to insert some values in a Microsoft access database using java.

I can an error however,

java.sql.SQLException: [Microsoft][ODBC Driver Manager] The specified DSN contains an architecture mismatch between the Driver and Application Exception in thread "main" java.lang.NullPointerException

To create the data source im using SysWoW64 > odbcad32 and adding it the datasource to system DNS. I say this as i have seen else where there are problems which occur with 64bit systems. However it still doesn't work for me.

Microsoft Office 32bit.

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;


public class RMIAuctionHouseJDBC {

    /**
     * @param args
     */
    public static void main(String[] args) {

        String theItem = "Car";
        String theClient="KHAN";
        String theMessage="1001";



Connection conn =null; // Create connection object

        try{
            Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
            System.out.println("Driver Found");
        } catch(Exception e) {
            System.out.println("Driver Not Found");
            System.err.println(e);
        }

        // connecting to database
        try{
            String database ="jdbc:odbc:Driver={Microsoft Access Driver (*.accdb)};DBQ=AuctionHouseDatabase.accdb;";

            conn = DriverManager.getConnection(database,"","");

            System.out.println("Conn Found");
        }
        catch(SQLException se) {
            System.out.println("Conn Not Found");
            System.err.println(se);
        }
        // Create select statement and execute it

        try{        
            /*String insertSQL = "INSERT INTO AuctionHouse VALUES (  "
                    +"'" +theItem+"', "  
                    +"'" +theClient+"', "
                    +"'" +theMessage+"')";  
            */

            Statement stmt = conn.createStatement();
            String insertSQL = "Insert into AuctionHouse VALUES ('Item','Name','Price')";

             stmt.executeUpdate(insertSQL);
            // Retrieve the results

            conn.close();
        } catch(SQLException se) {
            System.out.println("SqlStatment Not Found");
            System.err.println(se);
        }

    }

}

java.sql.SQLException: [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified at sun.jdbc.odbc.JdbcOdbc.createSQLException(Unknown Source) at sun.jdbc.odbc.JdbcOdbc.standardError(Unknown Source) at sun.jdbc.odbc.JdbcOdbc.SQLDriverConnect(Unknown Source) at sun.jdbc.odbc.JdbcOdbcConnection.initialize(Unknown Source)

© Stack Overflow or respective owner

Related posts about java

Related posts about jdbc