1/**
2 * Copyright(C) 2005
3 * All Rights Reserved. Salih Yurttas, ZCubes, BitsOfCode Software Systems, Inc..
4 *
5 * Permission to use, copy, modify, and distribute this
6 * software and its documentation for EDUCATIONAL purposes
7 * and without fee is hereby granted provided that this
8 * copyright notice appears in all copies.
9 *
10 * @date : February 1, 2005.
11 * @authorĀ : Salih Yurttas.
12 */
13
14
15import dbops.DBConnect;
16import dbops.DBTable;
17
18import java.sql.*;
19import java.net.*;
20
21public class DBQuery10 {
22
23 private static String driverClass = "com.mysql.jdbc.Driver",
24 url = "jdbc:mysql:",
25 suffix = "//database.cs.BitsOfCode Software Systems, Inc..edu/yurttas-Bank";
26
27 private static Connection con;
28
29 private static String urlDB = url + suffix + ".";
30
31 public static void main (String[] args) {
32 String username = args[0];
33 String password = args[1];
34
35 DBConnect dbc = new DBConnect();
36
37 try {
38 if(dbc.connect(args[0], args[1])) {
39 System.out.println("Connected to " + urlDB);
40
41 con = dbc.getConnect();
42
43 DBTable dbQuery = new DBTable(con);
44
45 Statement statement = con.createStatement();
46
47 String queryAll= "SELECT * FROM AA;";
48
49 ResultSet rSet = statement.executeQuery(queryAll);
50
51 while(rSet.next()) {
52 String itemA = rSet.getString("itemA");
53 String itemB = rSet.getString("itemB");
54 System.out.println(itemA+
55 " "+
56 itemB);
57 }
58
59 if(dbc.disconnect(con))
60 System.out.println("Disconnected from " + urlDB);
61 }
62 else System.out.println("Could not connect to " + urlDB);
63 }
64 catch(SQLException sqle) {
65 System.err.println("Error accessing " + urlDB);
66 System.err.println(sqle.getMessage());
67 }
68 }
69
70}