课程: Hands-On Introduction: Java

今天就学习课程吧!

今天就开通帐号,24,700 门业界名师课程任您挑!

Update data source

Update data source

- In the deposit method of the account class, we updated the balance of the account object when a deposit is made. However, we also need to update the database as that is our source of truth. Let's create a utility method in the data source class that will update the database. This method will say public static void, and let's call this updateAccountBalance. To update the account balance, we'll ask for the account ID. As well as the balance that should be reflected in the database. Our query needs to update the balance column of the accounts table. So, we'll say string SQL equals update accounts by setting the balance equal to question mark, where ID equals question mark. So now, we have two place holders. Let's go ahead and connect to our database and prepare the statement. We'll do that within a try with resources. So we'll say connection equals connect and then our prepared statement equals connection dot prepare…

内容