javadb/org/homelinux/largo/app/App.java
changeset 135 f837cf975e95
parent 123 07b2c0b991af
equal deleted inserted replaced
134:8325a0fc22cd 135:f837cf975e95
     1 package org.homelinux.largo.app;
     1 package org.homelinux.largo.app;
     2 
     2 
       
     3 import java.util.List;
       
     4 import java.sql.SQLException;
     3 import org.homelinux.largo.sql.client.DBClient;
     5 import org.homelinux.largo.sql.client.DBClient;
     4 
     6 
     5 public class App {
     7 public class App {
     6 	public static void main (String args[]) {
     8 	public static void main (String args[]) {
       
     9 		DBClient db = null;
       
    10 		int i = 0;
       
    11 
     7 		try {
    12 		try {
     8 			DBClient db = new DBClient ();
    13 			db = new DBClient ();
       
    14 			List<String> list = db.getTables ();
       
    15 
       
    16 			System.out.println ("TABLES IN THE CURRENT DATABASE");
       
    17 			for (String s : list) {
       
    18 				System.out.printf ("[%04d] %s%n", i++, s);
       
    19 			}
       
    20 			System.out.println ();
       
    21 
       
    22 			list = db.getColumns("EUROLEAGUE");
       
    23 			System.out.println ("COLUMN NAMES IN THIS TABLE");
       
    24 			for (String s : list) {
       
    25 				System.out.printf ("%s ", s);
       
    26 			}
       
    27 			System.out.printf ("%n%n");
       
    28 
       
    29 			i = db.update ("delete from euroleague where bonus>0");
       
    30 			System.out.printf ("Deleted: %3d lines%n", i);
     9 			db.query ("select * from euroleague order by team");
    31 			db.query ("select * from euroleague order by team");
    10 
    32 
    11 			while (db.hasNext ()) {
    33 			while (db.hasNext ()) {
    12 				System.out.println (db.getColumn (1));
    34 				System.out.println (db.getColumn ("team"));
    13 			}
    35 			}
    14 
    36 		} catch (SQLException sqle) {
    15 			db.close ();
    37 			System.out.println ("SQLException: " + sqle.getMessage());
    16 		} catch (Exception e) {
    38 		} catch (Exception e) {
    17 			e.printStackTrace ();
    39 			e.printStackTrace ();
       
    40 		} finally {
       
    41 			try {
       
    42 				if (db != null) {
       
    43 					System.out.println ("Disconnecting from database...");
       
    44 					db.disconnect();
       
    45 				}
       
    46 			} catch (Exception e) {
       
    47 				e.printStackTrace();
       
    48 			}
    18 		}
    49 		}
    19 	}
    50 	}
    20 }
    51 }