KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > sample > example > AccountCleaner


1 package sample.example;
2
3 public class AccountCleaner {
4
5     private Database database;
6
7     public AccountCleaner( Database database ) {
8         this.database = database;
9     }
10
11     public void fixCreditFlags() {
12         Rows rows = database.select( "SELECT account, balance, credit FROM accounts" );
13         database.start();
14         while( rows.hasNext() ) {
15             long account = rows.getLong( "account" );
16             long balance = rows.getLong( "balance" );
17             boolean credit = rows.getBoolean( "credit" );
18             if ( balance < 0 && credit ) {
19                 database.execute( "UPDATE accounts SET credit = false WHERE account = " + account );
20             }
21             else if ( balance >= 0 && ! credit ) {
22                 database.execute( "UPDATE accounts SET credit = true WHERE account = " + account );
23             }
24         }
25         database.commit();
26     }
27
28 }
29
Popular Tags