MCPcopy Create free account
hub / github.com/5zig/The-5zig-Mod / doUpdate

Method doUpdate

Utils/src/eu/the5zig/util/db/Database.java:101–123  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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);

Callers 1

runMethod · 0.95

Calls 3

getConnectionMethod · 0.95
getLoggerMethod · 0.95
closeResourcesMethod · 0.95

Tested by

no test coverage detected