public WOComponent executeUpdate() { EOModel m = EOModelGroup.defaultGroup().models().objectAtIndex(0); con = ERXJDBCConnectionBroker.connectionBrokerForModel(m).getConnection(); try { Statement s = con.createStatement(); int r = s.executeUpdate(sql); response = "result: " + r; } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } finally { ERXJDBCConnectionBroker.connectionBrokerForModel(m).freeConnection(con); } return context().page(); }
public WOComponent executeQuery() { EOModel m = EOModelGroup.defaultGroup().models().objectAtIndex(0); con = ERXJDBCConnectionBroker.connectionBrokerForModel(m).getConnection(); try { con.setAutoCommit(false); Statement s = con.createStatement(); ResultSet rs = s.executeQuery(sql); con.commit(); StringBuffer buf = new StringBuffer(); // append header buf.append("<table border=\"1\"><tr>"); ResultSetMetaData rsmd = rs.getMetaData(); int colcount = rsmd.getColumnCount(); for (int i = 1; i <= colcount; i++) { buf.append("<td>"); buf.append(rsmd.getColumnName(i)); buf.append("</td>"); } buf.append("</tr>"); while (rs.next()) { buf.append("<tr>"); for (int i = 1; i <= colcount; i++) { buf.append("<td>"); Object o = rs.getObject(i); buf.append(o == null ? "" : o.toString()); buf.append("</td>"); } buf.append("</tr>"); } buf.append("</table>"); response = buf.toString(); } catch (SQLException e) { response = ERXUtilities.stackTrace(e); } finally { ERXJDBCConnectionBroker.connectionBrokerForModel(m).freeConnection(con); } return context().page(); }