File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JDBC and the fly likes More Simplified version of the question bellow ! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "More Simplified version of the question bellow !" Watch "More Simplified version of the question bellow !" New topic
Author

More Simplified version of the question bellow !

Jan Michael Soan
Ranch Hand

Joined: Feb 08, 2003
Posts: 36
Hello;
I have created a password management program for my payroll system which can add new users but the problem is i can't compare the results if a new record is added to the database.
Each time i compare the new username and the new password the password dailog doesnt continue.
Here's the codes :
Assuming It 's on the JFrame b1 is the JButton:
b1.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e)
{
try {

// select statement 1 & 2
// Here is where all the Problem Starts. I dont know if the .next() method of resultset is the problem ...
Statement statement1 = connect.createStatement();
Statement statement2 = connect.createStatement();
String query1 = "SELECT Username FROM UserId";
String query2 = "SELECT Password FROM UserId";

ResultSet rs1 = statement1.executeQuery(query1);
ResultSet rs2 = statement2.executeQuery(query2);
rs1.next();
rs2.next();
String pass1 = "" + rs1.getString(1);
String pass2 = "" + rs2.getString(1);
String pass3 = new String(i2.getPassword());


// select statement 3 & 4
Statement statement3 = connect.createStatement();
Statement statement4 = connect.createStatement();
String query3 = "SELECT Username FROM Admin";
String query4 = "SELECT Password FROM ADmin";

ResultSet rs3 = statement3.executeQuery(query3);
ResultSet rs4 = statement4.executeQuery(query4);
rs3.next();
rs4.next();
String pass4 = "" + rs3.getString(1);
String pass5 = "" + rs4.getString(1);
String pass6 = new String(i2.getPassword());

// if - else statement for user
if ( pass1.equals( i1.getText() ) ) {
if ( pass2.equals( pass3 ) ) {
try {
Statement statement = connect.createStatement();
String query = "UPDATE UserSelect SET User='User'";
int result = statement.executeUpdate( query );
System.out.println("User - Initialized !");

statement.close();
}
catch ( SQLException sqley ) {
sqley.printStackTrace();
System.out.println( sqley.toString() );
}
Splash time = new Splash();
dispose();
}
else {
JOptionPane.showMessageDialog(null,"Incorrect Password. . .",
"Warning . . .",JOptionPane.WARNING_MESSAGE);
tryme1++;
if( tryme1 >= 3 )
{
JOptionPane.showMessageDialog(null,"Your not a valid user . . .",
"Error . . .",JOptionPane.ERROR_MESSAGE);
System.exit(0);
}
}
}

// if - else statement for admin
else if ( pass4.equals( i1.getText() ) ) {
if ( pass5.equals( pass6 ) ) {
try {
Statement statement = connect.createStatement();
String query = "UPDATE UserSelect SET User='Admin'";
int result = statement.executeUpdate( query );
System.out.println("Admin - Initialized !");

statement.close();
}
catch ( SQLException sqley ) {
sqley.printStackTrace();
System.out.println( sqley.toString() );
}
Splash time = new Splash();
dispose();
}
else {
JOptionPane.showMessageDialog(null,"Incorrect Password. . .",
"Warning . . .",JOptionPane.WARNING_MESSAGE);
tryme1++;
if( tryme1 >= 3 )
{
JOptionPane.showMessageDialog(null,"Your not a valid user . . .",
"Error . . .",JOptionPane.ERROR_MESSAGE);
System.exit(0);
}
}
}

// catch wrong username
else {
JOptionPane.showMessageDialog(null,"Incorrect Username . . .",
"Warning . . .",JOptionPane.WARNING_MESSAGE);
tryme2++;
if( tryme2 >= 3 )
{
JOptionPane.showMessageDialog(null,"Your not a valid user . . .",
"Error . . .",JOptionPane.ERROR_MESSAGE);
System.exit(0);
}
}
statement1.close();
statement2.close();
}
catch ( SQLException sqlex ) {
sqlex.printStackTrace();
}
}
});
b2.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e)
{
i1.setText("");
i2.setText("");
i3.setText("");
i4.setText("");
}
});
}

// Main method
public static void main( String args[] )
{
Password app = new Password();
app.addWindowListener(
new WindowAdapter() {
public void windowClosing( WindowEvent e )
{
System.exit( 0 );
}
}
);
}
}
it's an emergency, thanks God Bless!
Jan Michael Soan
Ranch Hand

Joined: Feb 08, 2003
Posts: 36
Results :
Each time I use this codes, only the 1st string is compared to the strings pass1 to pass6.
My purpose is to compare all the Usernames and all the passwords in my database which is named Firewall . . .
Thanks !
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: More Simplified version of the question bellow !