Executes a MySQL Update with a PreparedStatement and given fields. @param query The Prepared Statement Query. Use ? for fields. @param fields The Fields that should be inserted into the Statement.
(String query, Object... fields)
| 99 | * @param fields The Fields that should be inserted into the Statement. |
| 100 | */ |
| 101 | public int doUpdate(String query, Object... fields) { |
| 102 | Connection connection; |
| 103 | try { |
| 104 | connection = getConnection(); |
| 105 | } catch (NoConnectionException e) { |
| 106 | getLogger().debug(e); |
| 107 | return 0; |
| 108 | } |
| 109 | |
| 110 | PreparedStatement st = null; |
| 111 | try { |
| 112 | st = connection.prepareStatement(query); |
| 113 | for (int i = 0; i < fields.length; i++) { |
| 114 | st.setObject(i + 1, fields[i]); |
| 115 | } |
| 116 | return st.executeUpdate(); |
| 117 | } catch (SQLException e) { |
| 118 | getLogger().warn("Could not Execute MySQL Update " + query, e); |
| 119 | } finally { |
| 120 | closeResources(st); |
| 121 | } |
| 122 | return 0; |
| 123 | } |
| 124 | |
| 125 | public void updateWithGeneratedKeys(String query, Object... fields) { |
| 126 | updateWithGeneratedKeys(null, query, fields); |
no test coverage detected