Package net.hironico.minisql.utils
Class DbUtils
java.lang.Object
net.hironico.minisql.utils.DbUtils
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic StringgetJsonResultSet(DbConfig dbConfig, String sql) Utility to get the result of an SQL qeury into JSON formatted string.static List<Map<String,Properties>> getPropertiesResultSet(DbConfig dbConfig, String sql, String propSeparator, String kvSeparator) Convert the rows returned by the result set into a list of map associated properties.Serialize a resultset object into a List of Maps.
-
Constructor Details
-
DbUtils
public DbUtils()
-
-
Method Details
-
getJsonResultSet
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 querysql- 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 tosql- the common to get result frompropSeparator- 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
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:
-
dateTimeFormattimeFormat
-