Project

General

Profile

« Previous | Next » 

Revision 184

cleaned up code for getting options from the properties file, made the database connection inthe MetaCatUtil class use the properties file for the conneciton info

View differences:

DBQuery.java
31 31
 */
32 32
public class DBQuery {
33 33

  
34
  private static String defaultDB = "jdbc:oracle:thin:@localhost:1521:test";
35 34
  private Connection	conn = null;
36 35
  private String	parserName = null;
37 36

  
38 37
  /**
39 38
   * the main routine used to test the DBQuery utility.
39
   * <p>
40
   * Usage: java DBQuery <xmlfile>
40 41
   *
41
   * Usage: java DBQuery <xmlfile> <user> <password> [dbstring]
42
   *
43 42
   * @param xmlfile the filename of the xml file containing the query
44
   * @param user the username to use for the database connection
45
   * @param password the password to use for the database connection
46
   * @param dbstring the connection info to use for the database connection
47 43
   */
48 44
  static public void main(String[] args) {
49 45
     
50
     if (args.length < 4)
46
     if (args.length < 1)
51 47
     {
52 48
        System.err.println("Wrong number of arguments!!!");
53
        System.err.println("USAGE: java DBQuery " +
54
                           "<xmlfile> <parser> <user> <password> [dbstring]");
49
        System.err.println("USAGE: java DBQuery <xmlfile>");
55 50
        return;
56 51
     } else {
57 52
        try {
58 53
                    
59 54
          String xmlfile  = args[0];
60
          String parser   = args[1];
61
          String user     = args[2];
62
          String password = args[3];
63
          String dbstring = null;
64 55

  
65
          if (args.length <= 4) {
66
            dbstring = defaultDB;
67
          } else {
68
            dbstring = args[4];
69
          }
70

  
71 56
          // Open a connection to the database
72
          Connection dbconn = MetaCatUtil.openDBConnection( 
73
                              "oracle.jdbc.driver.OracleDriver",
74
                              dbstring, user, password);
57
          MetaCatUtil   util = new MetaCatUtil();
58
          Connection dbconn = util.openDBConnection();
75 59

  
76 60
          // Execute the query
77
          DBQuery queryobj = new DBQuery(dbconn, parser);
61
          DBQuery queryobj = new DBQuery(dbconn, util.getOption("saxparser"));
78 62
          FileReader xml = new FileReader(new File(xmlfile));
79 63
          Hashtable nodelist = null;
80 64
          nodelist = queryobj.findDocuments(xml);

Also available in: Unified diff