Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Some time back, I was in same problem to deal with. After some pondering over this design we decided to do it like below.</p> <pre><code>public static Properties execute(String string, String[] columnames) throws Exception { Properties resulProperties = er.executeQuery(string, columnames); return resulProperties; } </code></pre> <p>For some specific reason, I created a field in my class as given below</p> <pre><code>private static ExecuteRequest er = new ExecuteRequest(); </code></pre> <p>In <code>ExecuteRequest</code> class below code is used.</p> <pre><code>public Properties executeQuery(String sqlstatement, String[] columnNames) throws Exception { Properties prop = new Properties(); try { prop = creteProperty(sqlstatement, columnNames); } catch (Exception e) { mlogger.report("Error executing sql statement"); throw (e); } return prop; } public Properties creteProperty(String sqlstatement, String[] columnNames) throws Exception { Properties prop = new Properties(); try { PreparedStatement stmt = ConnectionManager.getInstance().prepareStatement(sqlstatement); ResultSet rs = stmt.executeQuery(); if (rs.next()) { for (int i = 0; i &lt; columnNames.length; i++) { String key = columnNames[i]; if (rs.getObject(key) != null) { String value = (rs.getObject(key).toString()); prop.setProperty(key, value); } else { String value = ""; prop.setProperty(key, value); } } } rs.close(); } catch (Exception e) { mlogger.report("Error executing sql statement"); throw (e); } return prop; } </code></pre> <p>You can use this approach as a solution.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload