Java examples for JDBC:ResultSet
sum Short to Database
import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Timestamp; public class Main{ public static void sumShort(String row, short value, String table, int id, Connection... con) { if (value == 0) return; String query = "UPDATE " + table + " SET " + row + " = " + row + " + ? WHERE id = ?"; try {//from www . ja v a 2 s . c o m Connection connection = con.length > 0 ? con[0] : MySqlManager .getConnection(); try (PreparedStatement stmt = connection .prepareStatement(query)) { stmt.setShort(1, value); stmt.setInt(2, id); stmt.executeUpdate(); } finally { if (con.length <= 0) { connection.close(); } } } catch (SQLException ignored) { } } public static void setShort(String row, short value, String table, int id, Connection... con) { String query = "UPDATE " + table + " SET " + row + " = ? WHERE id = ?"; try { Connection connection = con.length > 0 ? con[0] : MySqlManager .getConnection(); try (PreparedStatement stmt = connection .prepareStatement(query)) { stmt.setShort(1, value); stmt.setInt(2, id); stmt.executeUpdate(); } finally { if (con.length <= 0) { connection.close(); } } } catch (SQLException ignored) { } } public static void setInt(String row, int value, String table, int id, Connection... con) { String query = "UPDATE " + table + " SET " + row + " = ? WHERE id = ?"; try { Connection connection = con.length > 0 ? con[0] : MySqlManager .getConnection(); try (PreparedStatement stmt = connection .prepareStatement(query)) { stmt.setInt(1, value); stmt.setInt(2, id); stmt.executeUpdate(); } finally { if (con.length <= 0) { connection.close(); } } } catch (SQLException ignored) { } } }