JFrame SQLite Login Credentials Interaction Error

https://imgur.com/a/lTcz9uW

I'm making a currency exchange application in Java using JFrame. I've created a SQLite Database with user login credentials in the src directory of my project. My program correctly accesses the database. I have multiple accounts with filled in with credentials, but when I launch my application and enter correct information for a user to login, it hits my exception handling that the "username and password are invalid". Can anyone figure out a flaw in my logic that would cause my application to be incorrectly reading the database? I'm fairly sure my SQLite syntax for search query is correct.

github link to repository: https://github.com/JTSipowicz/Software-Engineering-Project

Posted Apr 28, 2020, 10:25 PM UTC

16
aelytra•

At https://github.com/JTSipowicz/Software-Engineering-Project/blob/aed60607a0708c7b6351f15a8a601f7149212b95/Application.java#L77:

while(resultSet.next()) {
	count = count++; // this line isn't correct
}

!for (int i = 0; i <= 100; i++) { count = count++; } // count still equals 0 at the end of the loop.!<

Hope this helps.

2
JSipowiczOP•

I feel like an idiot. Changed it to count = count + 1 and it works. Now I'm wondering why count++ doesn't work? Thanks for the help.

1
aelytra•

count++ is the postfix increment operator. It's equivalent to:

var tmp = count;
count = count + 1;
return tmp;

So when you combine that together with count = count++, you're assigning the previous value of count prior to incrementing it.. back into count. So nothing happens.

The prefix increment operator, ++count, increments first and returns the incremented value instead.

If you put count++; on its own without the assignment operator, your code would also work as expected. You can also have SQL do the counting for you with "select count(*) from blah where blah" - it'll return a result set with 1 row and 1 column with the number of rows.

2
JSipowiczOP•

Makes total sense now. I've been thinking too big; I'm coding this project pretty much all by myself. My group members aren't versed in Java. Crazy how 1 tiny mistake in logic throws everything off. Thanks so much for breaking it down for me. My knight in shining armor!

1
JSipowiczOP•

Just saw your explanation on mobile format. You’re the best!

1
aelytra•

:) thanks

2