Skip to content

Instantly share code, notes, and snippets.

@aemxn
Last active August 29, 2015 14:05

Revisions

  1. Aiman Baharum revised this gist Aug 26, 2014. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions gistfile1.java
    Original file line number Diff line number Diff line change
    @@ -13,6 +13,7 @@ public static String getSearchResult(String search) {

    buf.append("<h3>Search Result for <strong>" + search + "</strong></h3>");

    // returns true if there are rows in ResultSet
    while (rs.next()) {
    buf.append("<p><strong>Data Structure Type:</strong> " + rs.getString("data_structure_type") + "</br>");
    buf.append("<strong>Element Name:</strong> " + rs.getString("element_name") + "</br>");
    @@ -22,6 +23,7 @@ public static String getSearchResult(String search) {

    }

    // No rows found
    if (!rs.first()){
    buf.append("<p><strong>No search result</strong></p>");
    }
  2. Aiman Baharum renamed this gist Aug 26, 2014. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  3. Aiman Baharum created this gist Aug 26, 2014.
    56 changes: 56 additions & 0 deletions ProcessDAO
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,56 @@
    public static String getSearchResult(String search) {

    StringBuilder buf = new StringBuilder();

    String searchQuery = "SELECT * FROM data_structure WHERE element_name LIKE '%" + search + "%'";
    // String searchQuery = "SELECT * FROM data_structure WHERE data_structure_type LIKE '%" + search + "%' or element_name LIKE '%" + search + "%' or element_description LIKE '%" + search + "%' or rational LIKE '%" + search + "%' or field_namecode LIKE '%" + search + "%' or alias LIKE '%" + search + "%' or field_size LIKE '%" + search + "%' or element_owner LIKE '%" + search + "%'";

    try {

    currentCon = ConnectionManager.getConnection();
    stmt = currentCon.createStatement();
    rs = stmt.executeQuery(searchQuery);

    buf.append("<h3>Search Result for <strong>" + search + "</strong></h3>");

    while (rs.next()) {
    buf.append("<p><strong>Data Structure Type:</strong> " + rs.getString("data_structure_type") + "</br>");
    buf.append("<strong>Element Name:</strong> " + rs.getString("element_name") + "</br>");
    buf.append("<strong>Element Description:</strong> " + rs.getString("element_description") + "</br>");
    buf.append("<strong>Field Namecode:</strong> <code>" + rs.getString("field_namecode") + "</code></br>");
    buf.append("<strong>Alias:</strong> " + rs.getString("field_namecode") + "</p><hr/>");

    }

    if (!rs.first()){
    buf.append("<p><strong>No search result</strong></p>");
    }

    } catch (SQLException e) {
    System.out.println("Search failed: An Exception has occurred! " + e);
    } finally {
    if (rs != null) {
    try {
    rs.close();
    } catch (SQLException e) {
    rs = null;
    }
    }
    if (stmt != null) {
    try {
    stmt.close();
    } catch (SQLException e) {
    rs = null;
    }
    }
    if (currentCon != null) {
    try {
    currentCon.close();
    } catch (SQLException e) {
    }
    currentCon = null;
    }
    }

    return buf.toString();
    }