i made a program that have a database.. Here is my database looked now:
I already could retrieve the Username with the User Type when user login with their Username. But i have a problem now, the program run properly, the only thing is the program show all of the Username and User Type even though i login with Username: Fuhans.
What i want is the program only show the Logged In Username (e.g: i login with Username: Fuhans and the program show the message box where it display Username (Fuhans) and the User Type of that Username only (Administrator), not all of the Username at the database.
How do i solve this?
Here is my code: (Written using Java)
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 Username, UserType 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);
}
}
Very big thanks!