Commit a4b7ca3d by Patryk Czarnik

Jeszcze prostszy update

parent d5c93f8f
...@@ -7,26 +7,20 @@ import java.sql.SQLException; ...@@ -7,26 +7,20 @@ import java.sql.SQLException;
public class P05_ProstyUpdate { public class P05_ProstyUpdate {
public static void podwyzka(int zmiana, int min, int max) {
String sql = "UPDATE employees SET salary = salary + ? "
+ "WHERE salary BETWEEN ? AND ?" ;
try(Connection c = DriverManager.getConnection(Ustawienia.URL, Ustawienia.USER, Ustawienia.PASSWD);
PreparedStatement stmt = c.prepareStatement(sql)) {
stmt.setInt(1, zmiana);
stmt.setInt(2, min);
stmt.setInt(3, max);
int ile = stmt.executeUpdate(); // uwaga, tego używamy także dla insert czy delete
// Dokładnie mówiąc: ilu wierszy dotyczyło zapytanie.
System.out.println("Zaktualizowano " + ile + " wierszy");
} catch (SQLException e) {
e.printStackTrace();
}
}
public static void main(String[] args) { public static void main(String[] args) {
podwyzka(333, 10000, 20000); String sql = "UPDATE employees SET salary = salary + ? WHERE job_id = ?" ;
try(Connection c = DriverManager.getConnection(Ustawienia.URL, Ustawienia.USER, Ustawienia.PASSWD);
PreparedStatement stmt = c.prepareStatement(sql)) {
stmt.setInt(1, 333);
stmt.setString(2, "IT_PROG");
int ile = stmt.executeUpdate(); // uwaga, tego używamy także dla insert czy delete
// Dokładnie mówiąc: ilu wierszy dotyczyło zapytanie.
System.out.println("Zaktualizowano " + ile + " wierszy");
} catch (SQLException e) {
e.printStackTrace();
}
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment