Skip to content
Advertisement

Update data to SQL Server with While java

So i’m trying to input data into my sql server with condition, i printout the value and nothing is wrong with the method, but the prepare statement only add one same data to the table, here is my code

Here is the result when i print out the makan and trans

and here is the data in the table enter image description here

which the prepared statement only exceute the same value….

Advertisement

Answer

Your sql query

will update all records where Status = 'Tetap' instead of a single record at a time. Moreover, select * is pulling more data from your database, i.e. using more resources than your desired use case. I would recommend selecting fields that are required instead eg

In order to update separate records, using a unique identifier such as your ID column in the where condition in your sql statement will solve your issue. The recommended modifications have been included below:

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement