I would appreciate some help, I am building a Java Application using Netbeans 5.5 and a Ms SQL Server 2000 database. It is a program for a Video Store.
I am busy with an edit interface where the user can add a genre or movie or delete a movie from the database. But I need to make the user enter a username and password before any editing can be done.
I've created a JtextField for the USERNAME and a JPasswordField for the PASSWORD. I am trying to match the USERNAME and PASSWORD against the database.
The program does not return any errors, but if I press Login nothing happens. This is the part for the Login Screen:
Hi Ulf I am not sure what you mean, I have added an event ActionPerformed to jButton1 and written the database connection code inside the event.
Is that the correct way?
Joined: Mar 22, 2005
Well, it doesn't matter what's inside the action listener if it's not being run for some reason :-) Put a System.out.println statement at the beginning of the jButton1ActionPerformed method to check if it's actually being called.
Joined: Mar 04, 2009
Is the variable "data" be static if its in outside any method (...i mean, if its a variable declared at class level)! Although your middle part of the code is a bit complicated to look at.
No need to retrieve it in every loop. Putting un, pass and pw outside the loop would be better.
Also modify your SQL query to something like:
If it returns a row in a ResultSet, then the user name, password exists and this would make the redundant looping go away make would optimize the code a little.