Davian Ramsay

Greenhorn
+ Follow
since May 24, 2013
Davian likes ...
Eclipse IDE Java Windows
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Davian Ramsay

am not certain which textfield in the image you assign to the variable(f2) so my suggestions: JTextField would not be appropriate to display all the information in a large database because it will only display all the names in a single line so JTextArea would be more appropriate as it may display the data line by line, also to have that being done with the enter key you would then have to assign a KeyListener instead of an action Listener, so i would recommend doing a little reading up on them,
Are you saying that when the user goes to the text field and presses the enter button on the keyboard you want the information from the database to be displayed?, am i understanding correctly
i tried to rewrite the codes to see if i was able to solve the problem, but what i noticed is that your insert statement had no ( " ") to show if you were trying to input a string or and integer data type into your database, this is important as it is need to verify that the data type of the program matches that of the database..and equaling the connection variable to null is not necessary either(Connection con =null);

NB. When inputting sting in the database a (' ') is needed and none when inputting an integer or double data type.

I wasn't able to run it to see what the outcome was but take a shot and let me know what the error is if any received

regards





the has next() method in the code ( result.next() ) normally traverse through all the data in the stored database until there is not data left so any amount of data stored in the database the program will loop that amount of times..example if there is 4 usernames and passwords stored on the database, this will loop through all 4

10 years ago
thanks for your response, i do know the difference between the two and the reason why i created two separate IF statements like that is due to the fact that the same problem i am having now was also happening then but it had multiple displays "Invalid credentials " when it checked the data in the database so that why i created it that way and the display now only occur once.

here it is and the same problem still occurs
#thanks for the tip

10 years ago
Hello,

i am developing a program that will accept a username and a password from a user and compare it with the data stored in a database in Microsoft access if the data received match the data in the database it should then proceed to another screen, but the problem am having is that i created an IF statement that if the entered data is correct it proceeds to the next screen but its also doing that(when input data matches) but its showing that the input was also "invalid" as this was what i place in the code if the username is incorrect so it doing two things at once, is there anyway i can correct this..help would be appreciated

this is my codes below:


try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String sourceURL = "jdbc:odbc:KnutsfordDSN";//name of the stored dsn connected to the stored database
Connection con = DriverManager.getConnection(sourceURL);
java.sql.Statement st = con.createStatement();

ResultSet result = st.executeQuery("SELECT*FROM Passwords");//Password table in the database

System.out.println("Connection Made");//if connection was sucessful




while(result.next()){
String Usernames = result.getString("Usernames"); //username column in the password table in the database
String Passwords = result.getString("Passwords");//password column in the password table in the database

if (txtusername.getText().equals(Usernames)&& txtpassword.getText().equals(Passwords)){
Knutsford kd = new Knutsford(); //if usernames and password match this form will be displayed
kd.setVisible(true);
dispose();

}


}if (txtusername.getText().equals("admin") && txtpassword.getText().equals("admin")){
JOptionPane.showMessageDialog(null,"Admin Login");




}else {
JOptionPane.showMessageDialog(null,"Invalid Credentials");
}





}catch(ClassNotFoundException cnfe){
System.err.println(cnfe);

}catch(SQLException ex){
System.err.println("SQLException:"+ex.getMessage());

}//end of making the connection















10 years ago