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:

private void GetUsername(Connection conn, Statement state, ResultSet result)
        String driver = "sun.jdbc.odbc.JdbcOdbcDriver";

        String url = "jdbc:odbc:Database";

        conn = DriverManager.getConnection(url);

        state = conn.createStatement();

        String query = "select * from Member";

        result = state.executeQuery(query);

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


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

    catch (Exception e) 


        _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);


_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

3 Years
Discussion Span
Last Post by stultuske

this is not really a Java question, rather a sql question.
you'll need to add a where clause to your select statement, linking the username in the db to the name of the logged in user:

select * from members where username like 'Nies'

a bit like that.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.