javadb/org/homelinux/largo/app/App.java
author Markus Bröker <mbroeker@largo.dyndns.tv>
Wed, 02 May 2012 20:49:41 +0200
changeset 164 e1f4bba1097a
parent 135 f837cf975e95
permissions -rw-r--r--
Small Makefile changes committer: Markus Bröker <mbroeker@largo.homelinux.org>
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
100
a6d2add085d7 Apache Derby Examples...
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
     1
package org.homelinux.largo.app;
a6d2add085d7 Apache Derby Examples...
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
     2
135
f837cf975e95 DBClient: update, query and metadata
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 123
diff changeset
     3
import java.util.List;
f837cf975e95 DBClient: update, query and metadata
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 123
diff changeset
     4
import java.sql.SQLException;
100
a6d2add085d7 Apache Derby Examples...
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
     5
import org.homelinux.largo.sql.client.DBClient;
a6d2add085d7 Apache Derby Examples...
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
     6
a6d2add085d7 Apache Derby Examples...
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
     7
public class App {
a6d2add085d7 Apache Derby Examples...
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
     8
	public static void main (String args[]) {
135
f837cf975e95 DBClient: update, query and metadata
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 123
diff changeset
     9
		DBClient db = null;
f837cf975e95 DBClient: update, query and metadata
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 123
diff changeset
    10
		int i = 0;
f837cf975e95 DBClient: update, query and metadata
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 123
diff changeset
    11
100
a6d2add085d7 Apache Derby Examples...
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    12
		try {
135
f837cf975e95 DBClient: update, query and metadata
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 123
diff changeset
    13
			db = new DBClient ();
f837cf975e95 DBClient: update, query and metadata
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 123
diff changeset
    14
			List<String> list = db.getTables ();
f837cf975e95 DBClient: update, query and metadata
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 123
diff changeset
    15
f837cf975e95 DBClient: update, query and metadata
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 123
diff changeset
    16
			System.out.println ("TABLES IN THE CURRENT DATABASE");
f837cf975e95 DBClient: update, query and metadata
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 123
diff changeset
    17
			for (String s : list) {
f837cf975e95 DBClient: update, query and metadata
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 123
diff changeset
    18
				System.out.printf ("[%04d] %s%n", i++, s);
f837cf975e95 DBClient: update, query and metadata
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 123
diff changeset
    19
			}
f837cf975e95 DBClient: update, query and metadata
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 123
diff changeset
    20
			System.out.println ();
f837cf975e95 DBClient: update, query and metadata
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 123
diff changeset
    21
f837cf975e95 DBClient: update, query and metadata
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 123
diff changeset
    22
			list = db.getColumns("EUROLEAGUE");
f837cf975e95 DBClient: update, query and metadata
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 123
diff changeset
    23
			System.out.println ("COLUMN NAMES IN THIS TABLE");
f837cf975e95 DBClient: update, query and metadata
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 123
diff changeset
    24
			for (String s : list) {
f837cf975e95 DBClient: update, query and metadata
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 123
diff changeset
    25
				System.out.printf ("%s ", s);
f837cf975e95 DBClient: update, query and metadata
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 123
diff changeset
    26
			}
f837cf975e95 DBClient: update, query and metadata
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 123
diff changeset
    27
			System.out.printf ("%n%n");
f837cf975e95 DBClient: update, query and metadata
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 123
diff changeset
    28
f837cf975e95 DBClient: update, query and metadata
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 123
diff changeset
    29
			i = db.update ("delete from euroleague where bonus>0");
f837cf975e95 DBClient: update, query and metadata
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 123
diff changeset
    30
			System.out.printf ("Deleted: %3d lines%n", i);
100
a6d2add085d7 Apache Derby Examples...
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    31
			db.query ("select * from euroleague order by team");
a6d2add085d7 Apache Derby Examples...
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    32
a6d2add085d7 Apache Derby Examples...
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    33
			while (db.hasNext ()) {
135
f837cf975e95 DBClient: update, query and metadata
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 123
diff changeset
    34
				System.out.println (db.getColumn ("team"));
100
a6d2add085d7 Apache Derby Examples...
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    35
			}
135
f837cf975e95 DBClient: update, query and metadata
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 123
diff changeset
    36
		} catch (SQLException sqle) {
f837cf975e95 DBClient: update, query and metadata
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 123
diff changeset
    37
			System.out.println ("SQLException: " + sqle.getMessage());
100
a6d2add085d7 Apache Derby Examples...
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    38
		} catch (Exception e) {
a6d2add085d7 Apache Derby Examples...
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    39
			e.printStackTrace ();
135
f837cf975e95 DBClient: update, query and metadata
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 123
diff changeset
    40
		} finally {
f837cf975e95 DBClient: update, query and metadata
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 123
diff changeset
    41
			try {
f837cf975e95 DBClient: update, query and metadata
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 123
diff changeset
    42
				if (db != null) {
f837cf975e95 DBClient: update, query and metadata
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 123
diff changeset
    43
					System.out.println ("Disconnecting from database...");
f837cf975e95 DBClient: update, query and metadata
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 123
diff changeset
    44
					db.disconnect();
f837cf975e95 DBClient: update, query and metadata
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 123
diff changeset
    45
				}
f837cf975e95 DBClient: update, query and metadata
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 123
diff changeset
    46
			} catch (Exception e) {
f837cf975e95 DBClient: update, query and metadata
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 123
diff changeset
    47
				e.printStackTrace();
f837cf975e95 DBClient: update, query and metadata
Markus Bröker <mbroeker@largo.dyndns.tv>
parents: 123
diff changeset
    48
			}
100
a6d2add085d7 Apache Derby Examples...
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    49
		}
a6d2add085d7 Apache Derby Examples...
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    50
	}
a6d2add085d7 Apache Derby Examples...
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff changeset
    51
}