Commit a4b7ca3d by Patryk Czarnik

Jeszcze prostszy update

parent d5c93f8f
...@@ -7,16 +7,14 @@ import java.sql.SQLException; ...@@ -7,16 +7,14 @@ import java.sql.SQLException;
public class P05_ProstyUpdate { public class P05_ProstyUpdate {
public static void podwyzka(int zmiana, int min, int max) { public static void main(String[] args) {
String sql = "UPDATE employees SET salary = salary + ? " String sql = "UPDATE employees SET salary = salary + ? WHERE job_id = ?" ;
+ "WHERE salary BETWEEN ? AND ?" ;
try(Connection c = DriverManager.getConnection(Ustawienia.URL, Ustawienia.USER, Ustawienia.PASSWD); try(Connection c = DriverManager.getConnection(Ustawienia.URL, Ustawienia.USER, Ustawienia.PASSWD);
PreparedStatement stmt = c.prepareStatement(sql)) { PreparedStatement stmt = c.prepareStatement(sql)) {
stmt.setInt(1, zmiana); stmt.setInt(1, 333);
stmt.setInt(2, min); stmt.setString(2, "IT_PROG");
stmt.setInt(3, max);
int ile = stmt.executeUpdate(); // uwaga, tego używamy także dla insert czy delete int ile = stmt.executeUpdate(); // uwaga, tego używamy także dla insert czy delete
// Dokładnie mówiąc: ilu wierszy dotyczyło zapytanie. // Dokładnie mówiąc: ilu wierszy dotyczyło zapytanie.
...@@ -25,8 +23,4 @@ public class P05_ProstyUpdate { ...@@ -25,8 +23,4 @@ public class P05_ProstyUpdate {
e.printStackTrace(); e.printStackTrace();
} }
} }
public static void main(String[] args) {
podwyzka(333, 10000, 20000);
}
} }
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