Example #1
0
  public static String getVersion(Connection conn) throws SQLException {
    String method = "getVersion";
    int location = 1000;
    try {
      location = 2000;
      String value = "";

      location = 2100;
      Statement stmt = conn.createStatement();
      String strSQL =
          "SELECT CASE "
              + "WHEN POSITION ('HAWQ 2.0.1' in version) > 0 THEN 'HAWQ_2_0_1' "
              + "WHEN POSITION ('HAWQ 2.0.0' in version) > 0 THEN 'HAWQ_2_0_0' "
              + "WHEN POSITION ('HAWQ 1' in version) > 0 THEN 'HAWQ_1' "
              + "WHEN POSITION ('HAWQ' in version) = 0 AND POSITION ('Greenplum Database' IN version) > 0 THEN 'GPDB' "
              + "ELSE 'OTHER' END "
              + "FROM version()";
      if (debug) Logger.printMsg("Getting Variable: " + strSQL);

      location = 2200;
      ResultSet rs = stmt.executeQuery(strSQL);

      while (rs.next()) {
        value = rs.getString(1);
      }

      location = 2300;
      return value;

    } catch (SQLException ex) {
      throw new SQLException(
          "(" + myclass + ":" + method + ":" + location + ":" + ex.getMessage() + ")");
    }
  }
Example #2
0
  public static void main(String args[]) {
    int myport = 9090;
    Socket s;
    ServerSocket ss;
    BufferedReader fromSoc, fromKbd;
    PrintStream toSoc;
    String line, msg;
    try {
      s = new Socket("169.254.63.10", 6016);
      System.out.println("enter line");
      System.out.println("connected");
      toSoc = new PrintStream(s.getOutputStream());

      toSoc.println(myport);
      String url =
          "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)}; DBQ=D://db.mdb; DriverID=22;READONLY=true;";

      Connection con = DriverManager.getConnection(url, "", "");
      Statement st = con.createStatement();
      String ip = "169.254.63.10";
      int port = 6016;
      String video = "rooney";

      st.executeUpdate(
          " insert into p3 values('" + ip + "' , '" + port + "' , '" + video + "' );  ");

      fun();

    } catch (Exception e) {

      System.out.println("exception" + e);
    }
  }
Example #3
0
  public static void recieveTrafficRates(String IP, float upload, float download) {
    System.out.println("Insertion of Data into Database!");
    Connection con = null;
    String url = "jdbc:mysql://localhost:3306/";
    String dbName = "traffic_report";
    String driverName = "com.mysql.jdbc.Driver";
    String userName = "******";
    String password = "******";
    String IP_address = IP;

    float up = upload, down = download;

    try {
      Class.forName(driverName).newInstance();
      con = DriverManager.getConnection(url + dbName, userName, password);
      try {
        Statement st = con.createStatement();

        int val =
            st.executeUpdate(
                "INSERT current_traffic VALUES('" + IP + "','" + up + "','" + down + "')");

        System.out.println("Data Entry process successfully!");
      } catch (SQLException s) {
        System.out.println("Table all ready exists!" + s);
      }
      con.close();
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
Example #4
0
  public static void customStartAll(Connection conn) throws SQLException {
    String method = "customStartAll";
    int location = 1000;
    try {
      Statement stmt = conn.createStatement();

      int id = 0;
      int gpfdistPort = 0;
      String strSQL = "SELECT id\n";
      strSQL += "FROM os.custom_sql";

      ResultSet rs = stmt.executeQuery(strSQL);
      while (rs.next()) {
        id = rs.getInt(1);
        gpfdistPort = GpfdistRunner.customStart(OSProperties.osHome);

        strSQL = "INSERT INTO os.ao_custom_sql\n";
        strSQL +=
            "(id, table_name, columns, column_datatypes, sql_text, source_type, source_server_name, source_instance_name, source_port, source_database_name, source_user_name, source_pass, gpfdist_port)\n";
        strSQL +=
            "SELECT id, table_name, columns, column_datatypes, sql_text, source_type, source_server_name, source_instance_name, source_port, source_database_name, source_user_name, source_pass, "
                + gpfdistPort
                + "\n";
        strSQL += "FROM os.custom_sql\n";
        strSQL += "WHERE id = " + id;

        stmt.executeUpdate(strSQL);
      }
    } catch (SQLException ex) {
      throw new SQLException(
          "(" + myclass + ":" + method + ":" + location + ":" + ex.getMessage() + ")");
    }
  }
Example #5
0
  public static void duration() {
    connectDb();
    String sql = "select min(time), max(time), count(*) from " + tablename + ";";
    try {
      ResultSet rs = query.executeQuery(sql);
      rs.next();
      int numCols = rs.getMetaData().getColumnCount();
      String minTime = rs.getString(1);
      String maxTime = rs.getString(2);
      String numPackets = rs.getString(3);
      System.out.println(
          "Experiment "
              + tablename
              + "\n\tfrom: "
              + minTime
              + "\n\tto: "
              + maxTime
              + "\n\tpackets: "
              + numPackets);

    } catch (SQLException e) {
      System.out.println("SQL Exception: " + e);
      System.exit(1);
    }
  }
Example #6
0
  public static String getVariable(Connection conn, String name) throws SQLException {
    String method = "getVariable";
    int location = 1000;
    try {
      location = 2000;
      String value = "";

      location = 2100;
      Statement stmt = conn.createStatement();
      String strSQL = "SELECT os.fn_get_variable('" + name + "')";

      if (debug) Logger.printMsg("Getting Variable: " + strSQL);

      location = 2200;
      ResultSet rs = stmt.executeQuery(strSQL);

      while (rs.next()) {
        value = rs.getString(1);
      }

      location = 2300;
      return value;

    } catch (SQLException ex) {
      throw new SQLException(
          "(" + myclass + ":" + method + ":" + location + ":" + ex.getMessage() + ")");
    }
  }
Example #7
0
  public static void failJobs(Connection conn) throws SQLException {
    String method = "failJobs";
    int location = 1000;
    try {
      Statement stmt = conn.createStatement();

      String strSQL =
          "INSERT INTO os.ao_queue (queue_id, status, queue_date, start_date, end_date, "
              + "error_message, num_rows, id, refresh_type, target_schema_name, target_table_name, target_append_only, "
              + "target_compressed, target_row_orientation, source_type, source_server_name, source_instance_name, "
              + "source_port, source_database_name, source_schema_name, source_table_name, source_user_name, "
              + "source_pass, column_name, sql_text, snapshot) "
              + "SELECT queue_id, 'failed' as status, queue_date, start_date, now() as end_date, "
              + "'Outsourcer stop requested' as error_message, num_rows, id, refresh_type, target_schema_name, "
              + "target_table_name, target_append_only, target_compressed, target_row_orientation, source_type, "
              + "source_server_name, source_instance_name, source_port, source_database_name, source_schema_name, "
              + "source_table_name, source_user_name, source_pass, column_name, sql_text, snapshot "
              + "FROM os.queue WHERE status = 'queued'";

      stmt.executeUpdate(strSQL);

    } catch (SQLException ex) {
      throw new SQLException(
          "(" + myclass + ":" + method + ":" + location + ":" + ex.getMessage() + ")");
    }
  }
Example #8
0
  /* to search the DB table for req. video*/
  boolean search(String file) {

    boolean found = false;

    Connection con = null;
    String url =
        "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};  DBQ=D://db.mdb; DriverID=22;READONLY=true;";

    try {
      con = DriverManager.getConnection(url, "", "");
      try {
        Statement st = con.createStatement();
        ResultSet rs = st.executeQuery("SELECT video FROM p3");
        while (rs.next()) {
          String colvalue = rs.getString("video");
          if (colvalue.equalsIgnoreCase(file)) found = true;
        }

      } catch (SQLException s) {
        System.out.println("SQL statement is not executed!");
      }
    } catch (Exception e) {
      System.out.println(e);
    }
    return found;
  }
Example #9
0
  public static void collectPredicates(Model m, Collection target) throws ModelException {

    for (Enumeration en = m.elements(); en.hasMoreElements(); ) {

      Statement st = (Statement) en.nextElement();
      target.add(st.predicate());
    }
  }
Example #10
0
  public static void collectLiterals(Model m, Collection target) throws ModelException {

    for (Enumeration en = m.elements(); en.hasMoreElements(); ) {

      Statement st = (Statement) en.nextElement();
      if (st.object() instanceof Literal) target.add(st.object());
    }
  }
Example #11
0
  public static Hashtable getNodes(Model m) throws ModelException {

    Hashtable t = new Hashtable();
    for (Enumeration en = m.elements(); en.hasMoreElements(); ) {
      Statement s = (Statement) en.nextElement();
      t.put(s.subject(), s.subject());
      t.put(s.object(), s.object());
    }
    return t;
  }
Example #12
0
  // FIXME: use digest instead of size
  static void getReachable(Resource r, Model m, Model result) throws ModelException {

    int oldSize = result.size();
    Model directlyReachable = m.find(r, null, null);
    SetOperations.unite(result, directlyReachable);
    if (result.size() == oldSize) return;
    for (Enumeration en = directlyReachable.elements(); en.hasMoreElements(); ) {
      Statement t = (Statement) en.nextElement();
      if (t.object() instanceof Resource) getReachable((Resource) t.object(), m, result);
    }
  }
Example #13
0
  public static void clearTable() {
    connectDb();
    String sql = "delete from " + tablename + ";";
    try {
      query.executeUpdate(sql);

    } catch (SQLException e) {
      System.out.println("SQL Exception: " + e);
      System.exit(1);
    }
    System.out.println("Table Cleared Successfully");
  }
Example #14
0
  // returns list of statements
  public static void replaceMult(Statement st, NodeFactory f, Map o2n, Collection result)
      throws ModelException {

    List l1 = new ArrayList();
    replaceMultSPO(st, f, o2n, l1, st.subject(), 0);

    List l2 = new ArrayList();
    for (int i = 0; i < l1.size(); i++)
      replaceMultSPO((Statement) l1.get(i), f, o2n, l2, st.predicate(), 1);

    for (int i = 0; i < l2.size(); i++)
      replaceMultSPO((Statement) l2.get(i), f, o2n, result, st.object(), 2);
  }
Example #15
0
  /** returns true if old triples from r were removed */
  public static boolean setUniqueObject(
      Model r, Resource subject, Resource predicate, RDFNode object) throws ModelException {

    Model old = r.find(subject, predicate, null);
    SetOperations.subtract(r, old);
    Statement stmt = get1(old);

    if (subject == null && stmt != null) subject = stmt.subject();
    if (predicate == null && stmt != null) predicate = stmt.predicate();

    r.add(r.getNodeFactory().createStatement(subject, predicate, object));
    return !old.isEmpty();
  }
Example #16
0
  public static List getObjects(Model m, Resource subject, Resource predicate)
      throws ModelException {

    List result = new ArrayList();

    if (m == null || m.size() == 0) return result;

    for (Enumeration en = m.find(subject, predicate, null).elements(); en.hasMoreElements(); ) {

      Statement st = (Statement) en.nextElement();
      result.add(st.object());
    }
    return result;
  }
Example #17
0
  public static void emailAlert(Connection conn, String errorMsg) throws SQLException {
    String method = "emailAlert";
    int location = 1000;
    try {
      Statement stmt = conn.createStatement();

      String strSQL = "SELECT gp_elog('" + errorMsg + "',true)";
      ResultSet rs = stmt.executeQuery(strSQL);

    } catch (SQLException ex) {
      throw new SQLException(
          "(" + myclass + ":" + method + ":" + location + ":" + ex.getMessage() + ")");
    }
  }
Example #18
0
  /** Removes all triples which have something to do with the given namespace */
  public static Model removeNamespace(String ns, Model m) throws ModelException {

    Model res = m.duplicate();
    for (Enumeration en = m.duplicate().elements(); en.hasMoreElements(); ) {

      Statement t = (Statement) en.nextElement();
      if (t.subject().toString().startsWith(ns)
          || t.predicate().toString().startsWith(ns)
          || t.object().toString().startsWith(ns)) {
        //      System.err.println("REMOVING TRIPLE: " + t);
        res.remove(t);
      }
    }
    return res;
  }
Example #19
0
 public void dispose() {
   try {
     stmt.close();
     con.close();
   } catch (SQLException e) {
   }
 }
Example #20
0
  public static int insertReplTable(Connection conn, String targetSchema, String targetTable)
      throws SQLException {
    String method = "insertReplTable";
    int location = 1000;

    int numRows = 0;
    try {
      location = 2000;
      String replTargetSchema = externalSchema;

      location = 2100;
      String replTargetTable = getStageTableName(targetSchema, targetTable);

      location = 2200;
      String externalTable = getExternalTableName(replTargetSchema, replTargetTable);

      location = 2305;
      // truncate the stage table before loading
      truncateTable(conn, replTargetSchema, replTargetTable);

      location = 2400;
      Statement stmt = conn.createStatement();

      location = 2500;
      String strSQL =
          "INSERT INTO \""
              + replTargetSchema
              + "\".\""
              + replTargetTable
              + "\" \n"
              + "SELECT * FROM \""
              + externalSchema
              + "\".\""
              + externalTable
              + "\"";
      if (debug) Logger.printMsg("Executing SQL: " + strSQL);

      location = 2600;
      numRows = stmt.executeUpdate(strSQL);

      location = 2700;
      return numRows;
    } catch (SQLException ex) {
      throw new SQLException(
          "(" + myclass + ":" + method + ":" + location + ":" + ex.getMessage() + ")");
    }
  }
Example #21
0
  // FIXME: what if reification is an endless loop?
  public static void collectNamespaces(Statement st, Collection target) throws ModelException {

    if (st.subject() instanceof Statement) collectNamespaces((Statement) st.subject(), target);
    else collectNamespaces(st.subject(), target);

    collectNamespaces(st.predicate(), target);

    if (st.object() instanceof Statement) collectNamespaces((Statement) st.object(), target);
    else if (st.object() instanceof Resource) collectNamespaces((Resource) st.object(), target);
  }
Example #22
0
  public static boolean checkStageTable(Connection conn, String targetSchema, String targetTable)
      throws SQLException {
    String method = "checkStageTable";
    int location = 1000;

    try {
      location = 2000;
      boolean found = false;

      String stageTable = getStageTableName(targetSchema, targetTable);

      location = 2100;
      String strSQL =
          "SELECT NULL \n"
              + "FROM INFORMATION_SCHEMA.TABLES \n"
              + "WHERE table_schema = '"
              + externalSchema
              + "' \n"
              + "	AND table_name = '"
              + stageTable
              + "'";

      if (debug) Logger.printMsg("Executing sql: " + strSQL);

      location = 2200;
      Statement stmt = conn.createStatement();

      location = 2310;
      ResultSet rs = stmt.executeQuery(strSQL);

      location = 2400;
      while (rs.next()) {
        found = true;
      }

      location = 2500;
      return found;

    } catch (SQLException ex) {
      throw new SQLException(
          "(" + myclass + ":" + method + ":" + location + ":" + ex.getMessage() + ")");
    }
  }
Example #23
0
  public static boolean createSchema(Connection conn, String schema) throws SQLException {
    String method = "createSchema";
    int location = 1000;
    try {
      location = 2000;
      boolean found = false;

      String strSQL =
          "SELECT COUNT(*) \n"
              + "FROM INFORMATION_SCHEMA.SCHEMATA \n"
              + "WHERE SCHEMA_NAME = '"
              + schema
              + "'";

      location = 2100;
      Statement stmt = conn.createStatement();

      location = 2200;
      ResultSet rs = stmt.executeQuery(strSQL);

      location = 2306;
      while (rs.next()) {
        if (rs.getInt(1) > 0) found = true;
      }

      location = 2400;
      if (!(found)) {
        location = 2500;
        String schemaDDL = "CREATE SCHEMA \"" + schema + "\"";
        ;
        if (debug) Logger.printMsg("Schema DDL: " + schemaDDL);

        location = 2600;
        stmt.executeUpdate(schemaDDL);
      }

      location = 2700;
      return found;

    } catch (SQLException ex) {
      return true;
    }
  }
Example #24
0
  public static String getMax(Connection conn, String schema, String table, String columnName)
      throws SQLException {
    String method = "getMax";
    int location = 1000;

    try {
      location = 2000;
      String strSQL =
          "SELECT MAX(\""
              + columnName.toLowerCase()
              + "\") \n"
              + "FROM \""
              + schema
              + "\".\""
              + table
              + "\"";

      if (debug) Logger.printMsg("Executing sql: " + strSQL);

      String max = "-1";

      location = 2100;
      Statement stmt = conn.createStatement();

      location = 2200;
      ResultSet rs = stmt.executeQuery(strSQL);

      while (rs.next()) {
        max = rs.getString(1);
      }

      location = 2313;
      if (max == null) {
        max = "-1";
      }
      return max;

    } catch (SQLException ex) {
      throw new SQLException(
          "(" + myclass + ":" + method + ":" + location + ":" + ex.getMessage() + ")");
    }
  }
Example #25
0
  public static void truncateTable(Connection conn, String schema, String table)
      throws SQLException {
    String method = "truncateTable";
    int location = 1000;
    try {
      location = 2000;
      Statement stmt = conn.createStatement();

      location = 2100;
      String strSQL = "truncate table \"" + schema + "\".\"" + table + "\"";

      if (debug) Logger.printMsg("Truncating table: " + strSQL);

      location = 2200;
      stmt.executeUpdate(strSQL);
    } catch (SQLException ex) {
      throw new SQLException(
          "(" + myclass + ":" + method + ":" + location + ":" + ex.getMessage() + ")");
    }
  }
Example #26
0
  public static void createTable() {
    connectDb();
    String dataField = "";
    for (int i = 0; i < AM_HEADER_LENGTH + TOSH_DATA_LENGTH + CRC_LENGTH; i++) {
      dataField = dataField + ", " + "b" + Integer.toString(i) + " smallint";
    }
    String sql =
        "create table "
            + tablename
            + " (time timestamp without time zone, packetid serial"
            + dataField;
    sql += ", primary key (packetid) );";
    try {
      query.executeUpdate(sql);

    } catch (SQLException e) {
      System.out.println("SQL Exception: " + e);
      System.exit(1);
    }
    System.out.println("Initialise Table Successfully");
  }
Example #27
0
  public void login() {
    String driver = "oracle.jdbc.driver.OracleDriver";
    String url = "jdbc:oracle:thin:@localhost:1521:orcl";
    Connection con = null;
    Statement stmt = null;
    ResultSet rs = null;

    String id, pw, sql;
    try {
      Class.forName(driver);
      con = DriverManager.getConnection(url, "hr", "hr");
      stmt = con.createStatement();
      sql = "select * from chatuser where id = '" + lid.getText() + "'";
      rs = stmt.executeQuery(sql);
      if (rs.next()) {
        pw = rs.getString(2);
        nick = rs.getString(3);
        if (lpw.getText().equals(pw)) {
          jd.setVisible(false);
          setVisible(true);
        } else {
          lpw.setText("일치하지 않습니다.");
        }
      } else {
        lid.setText("일치하지 않습니다.");
      }
    } catch (Exception e1) {
      e1.printStackTrace();
      System.out.println("데이터 베이스 연결 실패!!");
    } finally {
      try {
        if (rs != null) rs.close();
        if (stmt != null) stmt.close();
        if (con != null) con.close();
      } catch (Exception e1) {
        System.out.println(e1.getMessage());
      }
    }
  }
Example #28
0
  public static Statement replaceNamespace(
      Statement st, String o, String n, NodeFactory f, Map o2n, Set resourcesToIgnore)
      throws ModelException {

    boolean replaced = false;
    Resource subj = st.subject();
    Resource pred = st.predicate();
    RDFNode obj = st.object();

    if (obj instanceof Resource
        && !(obj instanceof Statement)
        && o.equals(((Resource) obj).getNamespace())
        && (resourcesToIgnore == null || !resourcesToIgnore.contains(obj))) {

      replaced = true;
      Resource r = f.createResource(n, ((Resource) obj).getLocalName());
      if (o2n != null) o2n.put(obj, r);
      obj = r;
    }

    if (o.equals(subj.getNamespace())
        && (resourcesToIgnore == null || !resourcesToIgnore.contains(subj))) {

      replaced = true;
      Resource r = f.createResource(n, subj.getLocalName());
      if (o2n != null) o2n.put(subj, r);
      subj = r;
    }

    if (o.equals(pred.getNamespace())
        && (resourcesToIgnore == null || !resourcesToIgnore.contains(pred))) {

      replaced = true;
      Resource r = f.createResource(n, pred.getLocalName());
      if (o2n != null) o2n.put(pred, r);
      pred = r;
    }
    return replaced ? f.createStatement(subj, pred, obj) : st;
  }
Example #29
0
  public static void cancelJobs(Connection conn) throws SQLException {
    String method = "cancelJobs";
    int location = 1000;
    try {
      List<String> jobIdList = new ArrayList<String>();
      Statement stmt = conn.createStatement();

      String strSQL = "SELECT id FROM os.queue WHERE status = 'processing'";
      ResultSet rs = stmt.executeQuery(strSQL);
      while (rs.next()) {
        jobIdList.add(rs.getString(1));
      }

      for (String jobId : jobIdList) {
        strSQL = "SELECT os.fn_cancel_job(" + jobId + ")";
        rs = stmt.executeQuery(strSQL);
      }
    } catch (SQLException ex) {
      throw new SQLException(
          "(" + myclass + ":" + method + ":" + location + ":" + ex.getMessage() + ")");
    }
  }
Example #30
0
  public static void setupReplicationTables(
      Connection conn, String targetSchema, String targetTable, String columnName)
      throws SQLException {
    String method = "setupReplicationTables";
    int location = 1000;

    try {
      location = 2000;
      String archTable = getArchTableName(targetSchema, targetTable);

      location = 2100;
      String stageTable = getStageTableName(targetSchema, targetTable);

      location = 2200;
      String strSQL =
          "SELECT os.fn_replication_setup('"
              + targetSchema
              + "', '"
              + targetTable
              + "', '"
              + externalSchema
              + "', '"
              + stageTable
              + "', '"
              + archTable
              + "', '"
              + columnName
              + "')";

      location = 2312;
      Statement stmt = conn.createStatement();

      location = 2400;
      stmt.executeQuery(strSQL);
    } catch (SQLException ex) {
      throw new SQLException(
          "(" + myclass + ":" + method + ":" + location + ":" + ex.getMessage() + ")");
    }
  }