Class DbUtils

java.lang.Object
net.hironico.minisql.utils.DbUtils

public class DbUtils extends Object
  • Constructor Details

    • DbUtils

      public DbUtils()
  • Method Details

    • getJsonResultSet

      public static String getJsonResultSet(DbConfig dbConfig, String sql) throws SQLException
      Utility to get the result of an SQL qeury into JSON formatted string. JSON properties are deduced from the meta data produced by the result of the query. This method works only if the sqlk query is actually returning data as a result, that is, update queries will not work (most propbably).
      Parameters:
      dbConfig - the database config to use for running the provided query
      sql - the query to get the JSON result from
      Returns:
      the JSON formatted result of the common query
      Throws:
      SQLException
      Since:
      2.18.x
    • getPropertiesResultSet

      public static List<Map<String,Properties>> getPropertiesResultSet(DbConfig dbConfig, String sql, String propSeparator, String kvSeparator) throws Exception
      Convert the rows returned by the result set into a list of map associated properties. Each key is the column name and the value is converted as a set of properties if possible. this works only if the values are text based and parsed using the given string : propSeparator is used to identifies key/value pairs and kvSeparator is used to identifies key and value.
      Parameters:
      dbConfig - the config to connect to
      sql - the common to get result from
      propSeparator - used to split properties (aka key value pairs)
      kvSeparator - used to split key and value for each property
      Returns:
      list of mapped properties to a column
      Throws:
      Exception - in case of any problem
    • serialize

      public static List<Map<String,Object>> serialize(ResultSet rs) throws SQLException
      Serialize a resultset object into a List of Maps. Each map represent a row of the resultset wich key/value pairs are column names with their values. DATE, TIME and TIMESTAMP objects are formatted using the date format defined statically in this class. Please note that if passed a resultset object, then the resultset is NOT closed by this method.
      Throws:
      SQLException
      See Also:
      • dateTimeFormat
      • timeFormat