1

I am creating a GUI bank project in netbeans that uses mysql database. I set the account numbers as primary key and I want the user to deposit money only if they put in their correct account number. When I tried to do this, only one row works, how do I make so that whenever the account number is entered and the amount for the deposit is entered, it will update the balance column. Here is my query statement:

String Query = "UPDATE ACCOUNTINFO SET BALANCE = '"+txtAmount.getText()+"'
                WHERE ACCOUNTNUMBER = '"+txtAccountNum.getText()+"'";
3
  • whats the error that you are getting? Commented May 5, 2016 at 12:50
  • The error I am getting is that only the first account number (which is the first column in the database) gets deposited. Then it doesn't deposit anything for any other account number except for the first one. Commented May 7, 2016 at 22:34
  • 2
    I figured it out. I just created a new window for each deposit because it only updates the database one at a time. Commented May 7, 2016 at 22:45

4 Answers 4

1

Updating multiple columns works like this:

UPDATE table SET colum1 = value1, column2 = value2 WHERE key_column = compare_value;
Sign up to request clarification or add additional context in comments.

1 Comment

man, looks like you have a tipo in your profile I have startet, maybe started ?. I will delete this comment later. There is no way to send PM except from QAs...
0

You can make menu driven program. Firstly you print all the functions that is available like show balance, withdraw money,Deposite money,etc .Give numbers to choices and then take input number and then use switch case and match the choice and ask inputs accordingly like you want only acc number or acc number and amount. And after operation is complete you can ask user if he want continue ? Check if he types yes or no in do..while loops condition if he pressed yes then show menu again.

2 Comments

I created a homepage GUI where the user selects deposit, withdraw, balance, etc. So the above part is for the deposit function.
OK . Then you simply use UPDATE table_name SET col1= value, col2=value WHERE condition;
0

Remove + " which you have written before WHERE clause in your query. and its UPDATE not UPDATA Please correct it.

Comments

0
String Query = "UPDATE ACCOUNTINFO SET 
    BALANCE = '"+txtAmount.getText()+"',
    WITHDRAWL_LIMIT = '"+txtLimit.getText()+"'
  WHERE ACCOUNTNUMBER = '"+txtAccountNum.getText()+"'";

1 Comment

That is what I did except for the withdrawal limit. It only updates the first account number entered. If you enter another account number for the database, it does not deposit that amount the user enters for the account numbers.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.