0

I teach a very introductory Java class to vocational HS students. I have been trying to connect a simple Java project to a simple MS Access database, with 0 positive results.

I have created an MS Access database with four fields: ID (autonumber), Site (text), User (text), PW (text). I have populated with 4 simple records ("Adam", "Beth", "Chad", "Dana" for site, user, and pw). The database is saved in the root of the Java project folder.

I have tried a number of searches and results but cannot get the Java to connect. I get this error message: [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified

Can anyone tell me what I'm missing? Or maybe point me to a working example? Thanks, Mike

Oh, yeah, here's my current code:

// Global Class Variables
String filePathString = "C:\\Users\\mclarke\\Documents\\NetBeansProjects\\PasswordManager.accdb";
String strConnect = "jdbc:odbc:DRIVER=Microsoft Access Driver (*.mdb, *.accdb);DBQ=" + filePathString;

// GUI initComponents()
public PasswordManagerGUI() {
    initComponents();
    try {
        Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
        Connection con = DriverManager.getConnection(strConnect, "","");
        System.out.println("Connection Succesfull");
    } catch (Exception e) {
        System.err.println("Got an exception! ");
        System.err.println(e.getMessage());

    }
}

// Main()
public static void main(String args[]) {
    try {
        for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
            if ("Nimbus".equals(info.getName())) {
                javax.swing.UIManager.setLookAndFeel(info.getClassName());
                break;
            }
        }
    } catch (ClassNotFoundException ex){
    } catch (InstantiationException ex) {
    } catch (IllegalAccessException ex) {
    } catch (javax.swing.UnsupportedLookAndFeelException ex) {
    }
    java.awt.EventQueue.invokeLater(new Runnable() {
        public void run() {
            new PasswordManagerGUI().setVisible(true);
        }
    });
}
  • Silly question, but is the jdbc driver (which I presume is in a .jar file) on the classpath? For example, if one were using mysql, one would need the mysql driver .jar file. – KevinO Mar 30 '16 at 02:36
  • What version of Java? The JDBC-ODBC bridge has been removed. You might try [Jackess](http://jackcess.sourceforge.net/) **or** [UCanAccess](http://ucanaccess.sourceforge.net/site.html). – Elliott Frisch Mar 30 '16 at 02:44
  • Possible duplicate of [java.lang.ClassNotFoundException: sun.jdbc.odbc.JdbcOdbcDriver Exception occuring. Why?](http://stackoverflow.com/questions/22984438/java-lang-classnotfoundexception-sun-jdbc-odbc-jdbcodbcdriver-exception-occurin) – MaxG Mar 30 '16 at 02:48

0 Answers0