Yurttas/PL/DBL/postgres/F/02/00/01/03/DBQuery11.java

Revision as of 00:02, 5 November 2013 by MassBot1 (talk | contribs) (Created page with "<syntaxhighlight lang="java" line start="1" enclose="div">/** * Copyright(C) 2005 * All Rights Reserved. Salih Yurttas, ZCubes, BitsOfCode Software Systems, Inc.. * * P...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
 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 DBQuery11 {
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        String queryAll= "SELECT * FROM AA;";
46
47        ResultSet rSet = dbQuery.getStatement(queryAll);
48
49        while(rSet.next()) {
50          String itemA = rSet.getString("itemA");
51          String itemB = rSet.getString("itemB");
52          System.out.println(itemA+
53                             "   "+
54                             itemB);
55        }
56
57        if(dbc.disconnect(con)) 
58          System.out.println("Disconnected from " + urlDB);
59      }
60      else System.out.println("Could not connect to " + urlDB);
61    }
62    catch(SQLException sqle) {
63      System.err.println("Error accessing " + urlDB);
64      System.err.println(sqle.getMessage());
65    }
66  }
67
68}