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
- UCanAcess-2.0.6-bin.zip
- commons-lang-2.6.jar
- commons-logging-1.1.3.jar
- hsqldb-2.3.2
- 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) {
}