Example #1
0
    /**
     * Convenience method for selecting records. Ideally this should not be use, instead a custom
     * query for this table should be used.
     *
     * @param where sql where statement.
     * @param orderBy sql order by statement
     */
    public ResultSet select(String where, String orderBy) {
      ResultSet rs = null;
      java.sql.Statement stmnt = null;

      try {
        stmnt = GenOrmDataSource.createStatement();
        StringBuilder sb = new StringBuilder();
        sb.append(SELECT);
        sb.append(FROM);
        if (where != null) {
          sb.append(WHERE);
          sb.append(where);
        }

        if (orderBy != null) {
          sb.append(" ");
          sb.append(orderBy);
        }

        String query = sb.toString();
        rs = new SQLResultSet(stmnt.executeQuery(query), query, stmnt);
      } catch (java.sql.SQLException sqle) {
        try {
          if (stmnt != null) stmnt.close();
        } catch (java.sql.SQLException sqle2) {
        }

        throw new GenOrmException(sqle);
      }

      return (rs);
    }
  public String execute() throws Exception {
    try {
      Class.forName("oracle.jdbc.driver.OracleDriver");
      /*Establish a connection with a data source*/
      Connection con1 =
          DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:orcl", "yash", "yash");
      String str = "SELECT * FROM  employee";
      java.sql.Statement stmt = con1.createStatement();
      ResultSet rs = stmt.executeQuery(str);

      while (rs.next()) {
        if (id.equals(rs.getString(1))) {
          name = rs.getString(2);
          gen = rs.getString(9);
          address = rs.getString(4);

          phone = rs.getString(5);
          email = rs.getString(6);
          salary = rs.getString(7);
          dob = rs.getDate(8);
          doj = rs.getDate(10);
        }
      }
      con1.close();
    } catch (Exception e) {

    }
    return MANAGEEDIT;
  }
Example #3
0
 /**
  * Closes any underlying java.sql.Result set and java.sql.Statement that was used to create this
  * results set.
  */
 public void close() {
   try {
     m_resultSet.close();
     m_statement.close();
   } catch (java.sql.SQLException sqle) {
     throw new GenOrmException(sqle);
   }
 }
 /** Gets version number out of a database table. */
 public Version(java.sql.Statement st, String sqlTable) throws SQLException {
   ResultSet rs = st.executeQuery("select major,minor,rev from " + sqlTable);
   rs.next();
   major = rs.getInt("major");
   minor = rs.getInt("minor");
   rev = rs.getInt("rev");
   rs.close();
 }
Example #5
0
    /**
     * This resets the key generator from the values in the database Usefull if the generated key
     * has been modified via some other means Connection must be open before calling this
     */
    public synchronized void reset() {
      m_nextKey = 0;
      java.sql.Statement stmnt = null;
      java.sql.ResultSet rs = null;
      try {
        stmnt = GenOrmDataSource.createStatement();
        rs = stmnt.executeQuery(MAX_QUERY);

        if (rs.next()) m_nextKey = rs.getInt(1);
      } catch (java.sql.SQLException sqle) {
        // The exception may occur if the table does not yet exist
        if (WARNINGS) System.out.println(sqle);
      } finally {
        try {
          if (rs != null) rs.close();

          if (stmnt != null) stmnt.close();
        } catch (java.sql.SQLException sqle2) {
          throw new GenOrmException(sqle2);
        }
      }
    }
Example #6
0
    public DataPointKeyGenerator(javax.sql.DataSource ds) {
      m_nextKey = 0;
      java.sql.Connection con = null;
      java.sql.Statement stmnt = null;
      try {
        con = ds.getConnection();
        con.setAutoCommit(true);
        stmnt = con.createStatement();
        java.sql.ResultSet rs = stmnt.executeQuery(MAX_QUERY);
        if (rs.next()) m_nextKey = rs.getInt(1);

        rs.close();
      } catch (java.sql.SQLException sqle) {
        // The exception may occur if the table does not yet exist
        if (WARNINGS) System.out.println(sqle);
      } finally {
        try {
          if (stmnt != null) stmnt.close();

          if (con != null) con.close();
        } catch (java.sql.SQLException sqle) {
        }
      }
    }
  public void write_in_db(
      int try_id,
      int catch_id,
      String try_con,
      String catch_con,
      String method_try_between_con,
      String catch_exception,
      String previous_catch_con,
      String file_path,
      String package_name,
      String class_name,
      String method_name,
      int try_loc,
      int is_try_logged,
      int try_log_count,
      String try_log_levels,
      int is_catch_logged,
      int catch_log_count,
      String catch_log_levels,
      int have_previous_catches,
      int previous_catches_logged,
      int is_return_in_try,
      int is_return_in_catch,
      int is_catch_object_ignore,
      int is_interrupted_exception,
      int is_thread_sleep_try,
      int throw_throws_try,
      int throw_throws_catch,
      int if_in_try,
      int if_count_in_try,
      int is_assert_try,
      int is_assert_catch,
      int previous_catches_log_count,
      int catch_depth,
      int is_method_have_param,
      String method_param_as_string_original,
      String method_param_as_string,
      String method_param_type,
      String method_param_name,
      int method_param_count,
      String method_call_names_try,
      int method_call_count_try,
      String operators_in_try,
      int operators_count_try,
      String variables_in_try,
      int variables_count_try,
      String method_call_names_till_try,
      int method_call_count_till_try,
      String operators_till_try,
      int operators_count_till_try,
      String variables_till_try,
      int varaibles_count_till_try,
      int loc_till_try,
      int is_till_try_logged,
      int till_try_log_count,
      String till_try_log_levels,
      int is_return_till_try,
      int throw_throws_till_try,
      int if_in_till_try,
      int if_count_in_till_try,
      int is_assert_till_try) {

    util3_met utm = new util3_met();
    // method_content = utm.replace_quotes_string(method_content);
    method_try_between_con = utm.replace_quotes_string(method_try_between_con);
    try_con = utm.replace_quotes_string(try_con);
    catch_con = utm.replace_quotes_string(catch_con);

    String insert_str =
        "insert into "
            + table
            + " values("
            + try_id
            + ","
            + catch_id
            + ",\""
            + try_con
            + "\",\""
            + catch_con
            + "\",\""
            + method_try_between_con
            + "\",\""
            + catch_exception
            + "\",\""
            + previous_catch_con
            + "\",\""
            + file_path
            + "\",\""
            + package_name
            + "\",\""
            + class_name
            + "\",\""
            + method_name
            + "\","
            + try_loc
            + ","
            + is_try_logged
            + ","
            + try_log_count
            + ",\""
            + try_log_levels
            + "\","
            + is_catch_logged
            + ","
            + catch_log_count
            + ",\""
            + catch_log_levels
            + "\","
            + have_previous_catches
            + ","
            + previous_catches_logged
            + ","
            + is_return_in_try
            + ","
            + is_return_in_catch
            + ","
            + is_catch_object_ignore
            + ","
            + is_interrupted_exception
            + ","
            + is_thread_sleep_try
            + ","
            + throw_throws_try
            + ","
            + throw_throws_catch
            + ","
            + if_in_try
            + ","
            + if_count_in_try
            + ","
            + is_assert_try
            + ","
            + is_assert_catch
            + ","
            + previous_catches_log_count
            + ","
            + catch_depth
            + ","
            + is_method_have_param
            + ",\""
            + method_param_as_string_original
            + "\",\""
            + method_param_as_string
            + "\",\""
            + method_param_type
            + "\",\""
            + method_param_name
            + "\","
            + method_param_count
            + ",\""
            + method_call_names_try
            + "\","
            + method_call_count_try
            + ",'"
            + operators_in_try
            + "',"
            + operators_count_try
            + ",'"
            + variables_in_try
            + "',"
            + variables_count_try
            + ",'"
            + method_call_names_till_try
            + "',"
            + method_call_count_till_try
            + ",'"
            + operators_till_try
            + "',"
            + operators_count_till_try
            + ",'"
            + variables_till_try
            + "',"
            + varaibles_count_till_try
            + ","
            + loc_till_try
            + ","
            + is_till_try_logged
            + ","
            + till_try_log_count
            + ",\""
            + till_try_log_levels
            + "\","
            + is_return_till_try
            + ","
            + throw_throws_till_try
            + ","
            + if_in_till_try
            + ","
            + if_count_in_till_try
            + ","
            + is_assert_till_try
            + ")";

    System.out.println("Insert str=" + insert_str);
    System.out.println("Try id=" + try_id);

    /*if("ajp".equalsIgnoreCase(package_name))
    {
    	System.out.println("Hi for ajp:"+ package_name);
    	//interupt();

    }*/
    try {

      System.out.println("I am writing");
      stmt = conn.createStatement();
      stmt.executeUpdate(insert_str);
    } catch (SQLException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
  }
  public void insert(
      String if_block,
      String if_expr,
      String method_if_between_con,
      int loc_till_if,
      int is_till_if_logged,
      int till_if_log_count,
      String till_if_log_levels,
      String operators_till_if,
      int operators_count_till_if,
      String variables_till_if,
      int variables_count_till_if,
      String method_call_names_till_if,
      int method_call_count_till_if,
      int is_return_till_if,
      int throw_throws_till_if,
      int if_in_till_if,
      int if_count_in_till_if,
      int is_assert_till_if,
      int is_method_have_param,
      String method_param_as_string_original,
      String method_param_as_string,
      String method_param_type,
      String method_param_name,
      int method_param_count,
      int is_return_in_if,
      int throw_throws_if,
      int is_assert_if,
      int is_null_condition_if,
      int is_instance_of_condition_if,
      String package_name,
      String class_name,
      String method_name,
      String file_path,
      int is_if_logged,
      int if_log_count,
      String if_log_levels) {

    id++;
    //  int logged= 0;

    /*if(log_count!=0)
    {
    	logged =1;
    }*/

    util_met utm = new util_met();
    method_if_between_con = utm.replace_quotes_string(method_if_between_con);
    if_block = utm.replace_quotes_string(if_block);

    method_if_between_con = "I am not inserting too large for if";
    if_block = "too large not inserting if block";

    if_expr = utm.replace_quotes_string(if_expr);
    file_path = file_path.replace("\\", "\\\\");

    String insert_str =
        " insert into "
            + table
            + " values("
            + id
            + ",'"
            + if_block
            + "','"
            + if_expr
            + "','"
            + method_if_between_con
            + "',"
            + loc_till_if
            + ","
            + is_till_if_logged
            + ","
            + till_if_log_count
            + ",'"
            + till_if_log_levels
            + "','"
            + operators_till_if
            + "',"
            + operators_count_till_if
            + ",'"
            + variables_till_if
            + "',"
            + variables_count_till_if
            + ",'"
            + method_call_names_till_if
            + "',"
            + method_call_count_till_if
            + ","
            + is_return_till_if
            + ","
            + throw_throws_till_if
            + ","
            + if_in_till_if
            + ","
            + if_count_in_till_if
            + ","
            + is_assert_till_if
            + ","
            + is_method_have_param
            + ",'"
            + method_param_as_string_original
            + "','"
            + method_param_as_string
            + "','"
            + method_param_type
            + "','"
            + method_param_name
            + "',"
            + method_param_count
            + ","
            + is_return_in_if
            + ","
            + throw_throws_if
            + ","
            + is_assert_if
            + ","
            + is_null_condition_if
            + ","
            + is_instance_of_condition_if
            + ",'"
            + package_name
            + "','"
            + class_name
            + "','"
            + method_name
            + "', '"
            + file_path
            + "',"
            + is_if_logged
            + ","
            + if_log_count
            + ",'"
            + if_log_levels
            + "'"
            + " )";

    System.out.println("Insert str" + insert_str);
    try {
      if (conn == null) {
        // System.out.println("I am null");
      }
      stmt = conn.createStatement();
      stmt.executeUpdate(insert_str);
    } catch (SQLException e) { // TODO Auto-generated catch block
      e.printStackTrace();
    }
  }
Example #9
0
  private List<Object[]> getCustomStgUsers(boolean usedb2) {
    List<Object[]> listData = new ArrayList<Object[]>();
    String ServerName = "";
    int PortNumber;
    String DatabaseName = "";
    java.util.Properties properties;
    String url = "";
    java.sql.Connection con = null;

    if (usedb2) {
      ServerName = synDB.getConfigProperties("SERVER_NAME");
      PortNumber = Integer.parseInt(synDB.getConfigProperties("PORT_NUMBER"));
      DatabaseName = synDB.getConfigProperties("DATABASE");
      properties = new java.util.Properties();
      properties.put("user", synDB.getConfigProperties("USER"));
      properties.put("password", synDB.getConfigProperties("PASSWORD"));
      properties.put("sslConnection", "true");
      System.setProperty("javax.net.ssl.trustStore", synDB.getConfigProperties("CACERTS_PATH"));
      System.setProperty("javax.net.ssl.trustStorePassword", "changeit");
      System.setProperty("db2.jcc.charsetDecoderEncoder", "3");
      url = "jdbc:db2://" + ServerName + ":" + PortNumber + "/" + DatabaseName;

      try {
        new DB2Driver();
      } catch (Exception e) {
        System.out.println("Error: failed to load Db2 jcc driver.");
      }
    } else {
      ServerName = synDB.getConfigProperties("SERVER_NAME");
      PortNumber = Integer.parseInt(synDB.getConfigProperties("PORT_NUMBER"));
      DatabaseName = synDB.getConfigProperties("DATABASE");

      properties = new java.util.Properties();
      properties.put("user", synDB.getConfigProperties("USER"));
      properties.put("password", synDB.getConfigProperties("PASSWORD"));
      url = "jdbc:postgresql://" + ServerName + ":" + PortNumber + "/" + DatabaseName;
    }

    try {
      System.out.println("url: " + url);
      con = java.sql.DriverManager.getConnection(url, properties);
      try {
        String sql =
            "SELECT a.ID_NRIC, FIRST_NAME, LAST_NAME, MOBILE, EMAIL, ACCOUNT_STATUS, AGENT_CODE, AGENCY, NEED2FA, NEEDTNC, USER_TYPE, USER__SUB_TYPE, a.CREATED_DATE, b.ROLE_NAME "
                + "FROM CUSTOM_STG_USER a INNER JOIN CUSTOM_STG_USER_ROLE b ON (b.ID_NRIC=a.ID_NRIC) ";
        StringBuilder sbSQLSTGUser = new StringBuilder();
        sbSQLSTGUser.append(sql);

        System.out.println("Select from PSE.CUSTOM_STG_USER DB2: " + sbSQLSTGUser.toString());
        java.sql.Statement ps = con.createStatement();
        java.sql.ResultSet rs = ps.executeQuery(sbSQLSTGUser.toString());
        System.out.println("get data....");

        Object[] objArrays = new Object[14];
        while (rs.next()) {
          objArrays = new Object[14];
          objArrays[0] = rs.getString(1);
          objArrays[1] = rs.getString(2);
          objArrays[2] = rs.getString(3);
          objArrays[3] = rs.getString(4);
          objArrays[4] = rs.getString(5);
          objArrays[5] = rs.getString(6);
          objArrays[6] = rs.getString(7);
          objArrays[7] = rs.getString(8);
          objArrays[8] = rs.getString(9);
          objArrays[9] = rs.getString(10);
          objArrays[10] = rs.getString(11);
          objArrays[11] = rs.getString(12);
          objArrays[12] = rs.getString(13);
          objArrays[13] = rs.getString(14);
          listData.add(objArrays);
          System.out.println(
              "GET FROM DB2 | ID_NRIC:"
                  + objArrays[0]
                  + ", FIRST_NAME:"
                  + objArrays[1]
                  + ", LAST_NAME:"
                  + objArrays[2]
                  + ", MOBILE:"
                  + objArrays[3]
                  + ", EMAIL:"
                  + objArrays[4]
                  + ", ACCOUNT_STATUS:"
                  + objArrays[5]
                  + ", AGENT_CODE:"
                  + objArrays[6]
                  + ", AGENCY:"
                  + objArrays[7]
                  + ", NEED2FA:"
                  + objArrays[8]
                  + ", NEEDTNC:"
                  + objArrays[9]
                  + ", USER_TYPE:"
                  + objArrays[10]
                  + ", USER_SUB_TYPE:"
                  + objArrays[11]
                  + ", CREATED_DATE :"
                  + objArrays[12]
                  + ", ROLE_NAME :"
                  + objArrays[13]);
        }
      } catch (Exception e) {
        e.printStackTrace();
        System.out.println("select is failing1");
      }

      if (con != null) {
        try {
          con.close();
          con = null;
        } catch (Exception e) {
        }
      }
    } catch (Exception e) {
      e.printStackTrace();
    }

    return listData;
  }