I was doing my login access with ms access database (accdb), supposed can work but after i upgrade to java 8, it no longer able to support odbc and i was struggled to solve this problem, and it gave me the ClassNotFoundException

list of library i have in my netbean project

  1. UCanAcess-2.0.6-bin.zip
  2. commons-lang-2.6.jar
  3. commons-logging-1.1.3.jar
  4. hsqldb-2.3.2
  5. jackcess-2.0.4.jar

firstly i was thought maybe because of the library, but it still gave me the ClassNotFoundException: net.ucanaccess.jdbc.UcanaccessDriver

below is my coding

private Connection con;
    private Statement st;
    private ResultSet rs;which



public void connect() throws SQLException{
        try {
            Class.forName("net.ucanaccess.jdbc.UcanaccessDriver");
            con = DriverManager.getConnection("jdbc:ucanaccess://C:/Users/ChengLeeMing/Desktop/APU work/DCOM/Tutorial/MyChat/MyChatDatabase.accdb");
        } catch (ClassNotFoundException e) {
            JOptionPane.showMessageDialog(null, e);
        }
    }

Login button (help me check anything need to change to access the login authentication, and which part should i do the parameter, the statements that have been // were used when i was using java 7 with odbc)

String user_login = "Select * from MyChatUser where Username = ? and Userpass = ?";
        try {
            st = con.createStatement();
          //  st.setString(1, txtuser.getText());
           //    st.setString(2, txtpass.getText());
            rs = st.executeQuery(user_login);
            if ((txtuser.getText().trim().length() == 0) || (txtpass.getText().trim().length() == 0)) {
                JOptionPane.showMessageDialog(null, "Insert Username and Password!");
            } else if (rs.next()) {
                JOptionPane.showMessageDialog(null, "Login Success!");
                userEmail = rs.getString("Email");
                userName = rs.getString("ChatName");
                LoginPanel.setVisible(false);
                lblusername.setText("User Name : " + userName);
                //   btlogout.setVisible(true);
                btemail.setVisible(true);
                btfile.setVisible(true);
                ChatPanel.setVisible(true);
                PanelMenu.setVisible(true);
                UserPanel.setVisible(true);
                this.setName(userName);
                this.setEmail(userEmail);
                this.pack();
                this.setLocationRelativeTo(null);
            } else {
                JOptionPane.showMessageDialog(null, "Invalid Username or Password!");
            }
        } catch (Exception e) {
        }

Never do this when writing new code:

} catch (Exception e) {
}

If/when there is an error you just told Java that you didn't want to know anything about it, and please discard the detailed error message that Java just created for you.
ALWAYS put an e.printStackTrace(); in your catch blocks until/unless you have a good reason to do something else.

UCanAcess-2.0.6-bin.zip looks like a distribution package - you need a .jar file. Start by expanding the zip and look for the jar file

i already drag out from the ucanaccess zip file and addin to library, but still cannot access the MS database, is there anthing wrong with my database connection statement?

ClassNotFoundException: net.ucanaccess.jdbc.UcanaccessDriver

that message is pretty explicit. After extracting fromn the zip file and adding to NetBeans librray, do you have the jar that contains net.ucanaccess.jdbc.UcanaccessDriver.class in the list of libraries?

Have you kept all the jar files in jre/ext/lib/ ?
L.Sankaranarayanan

Please add ucanaccess-3.0.7.jar which is available inside UCanAcess-2.0.6-bin.zip ....

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.