Click here to Skip to main content
15,920,438 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hai everyone, i have a problem, currently i am developing software using Java (netbeans):

Currently my database looked like this:

Username and UserType
Fuhans and Administrator
Nies and Member

When i login with Username: Nies

The program respond, but it gave me the dialog box where both Username are displayed. I want only when i login with Username: Nies, the program also gave me the dialog box where only that Username will be displayed..

How do i fix that?

Here is the code that display a username and dialog box:

C#
private void GetUsername(Connection conn, Statement state, ResultSet result)
    {
        try
        {
            String driver = "sun.jdbc.odbc.JdbcOdbcDriver";
            Class.forName(driver);

            String url = "jdbc:odbc:Database";

            conn = DriverManager.getConnection(url);

            state = conn.createStatement();

            String query = "select * from Member";

            result = state.executeQuery(query);

            while(result.next())
            {
                user = result.getString("Username");
                userType = result.getString("UserType");

                _userInformation.setUser(user);
                _userInformation.setUserType(userType);

                _sound.PlaySound(1);
                _infoBox.ShowMessageBox("Welcome! " + _userInformation.getUser() + " - " + _userInformation.getUserType() + " ", "Welcome" , 1);
            }
        }

        catch (Exception e)
        {
            System.err.println(e.getMessage());

            _sound.PlaySound(2);

            _infoBox.ShowMessageBox(e.getMessage(), "Error", 2);

            _reminder = new Reminder(1);

            JOptionPane.showOptionDialog(null, "Program will be closed due to error", "Error", JOptionPane.DEFAULT_OPTION, JOptionPane.INFORMATION_MESSAGE, null, new Object[]{}, null);

            System.exit(0);
        }
    }


_infoBox.ShowMessageBox is the instance ShowMessageBox function inside InfoBox class where that function store JOptionPane.

I want only the current login user in the program that will be detected, not all the users in the database.

How do i solve that? Thanks
Posted
Comments
Peter Leow 17-Nov-13 20:16pm    
your sql query "select * from Member" is retrieving all records, you need to add a WHERE clause to state that you want a particular username, but then you did not pass your username as parameter to this GetUsername method.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900