Menu

Using UCanAccess to netbeans. Can't update my access file using netbeans

Help
2016-02-28
2016-02-28
  • Jan Bien A. Daniel

    So here am I trying to work with my assignment. I think I'm doing it right but when I open my userlogin.accdb my tables didn't update. I don't know what to do anymore, I tried everything but unfortunately it didn't work.

    here's my code. I Hope you can help me guys.

    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.sql.*;
    public class SignUp extends JFrame implements ActionListener{
        final int width = 400;
        final int height = 200;
        JLabel userr = new JLabel("UserName");
        JLabel passs = new JLabel ("Password");
        JTextField usernamee = new JTextField (10);
        JPasswordField passwordd = new JPasswordField(10);
        JButton confirm = new JButton ("Confirm");
        String user = usernamee.getText();
        char pass[] = passwordd.getPassword();
        public SignUp(){
            super("SIGNUP");
            setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
            setSize(width,height);
            setLayout (new FlowLayout());
            add(userr);
            add(usernamee);
            add(passs);
            add(passwordd);
            add(confirm);
            confirm.addActionListener(this);
        }
        public void actionPerformed(ActionEvent a){
            String url = "jdbc:odbc:JavaCourse";
            String query = "SELECT UserName,Password FROM userlogin";
            try{
                Connection con = DriverManager.getConnection("jdbc:ucanaccess://C:\\Users\\Jeybee\\Desktop\\UserLogIn.accdb");
                Statement stmt = con.createStatement();
                ResultSet rs = stmt.executeQuery(query);
    
                stmt.executeUpdate("INSERT INTO userlogin " + "(Username,Password)"+ "VALUES ('" + user + "' + , ' " + pass + "')" );
            }
                catch(SQLException ex){
                        while (ex!=null){
                             System.out.println("SQL Exception: " + ex.getMessage());
                              ex = ex.getNextException();
                        }
                        }
    
            }
        public static void main(String[] args){
              SignUp sign = new SignUp();
              sign.setVisible(true);
        }
        }
    
     

    Last edit: Gord Thompson 2016-02-28
  • Gord Thompson

    Gord Thompson - 2016-02-28

    I'm not sure about NetBeans, but Eclipse won't even compile your code. For one thing, your connection URL is invalid:

    Connection con = DriverManager.getConnection("jdbc:ucanaccess://C:\Users\Jeybee\Desktop\UserLogIn.accdb");
    

     
    is malformed because of the bare backslashes in the file path

    BadEscape.png

     
    try using forward slashes instead:

    Connection con = DriverManager.getConnection("jdbc:ucanaccess://C:/Users/Jeybee/Desktop/UserLogIn.accdb");
    
     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.