package zajecia.postgresql;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;

import javax.swing.JOptionPane;

public class Podwyzka1 {

	public static void main(String[] args) {
		String url = "jdbc:postgresql://localhost/hr";
		try(Connection c = DriverManager.getConnection(url, "kurs", "abc123")) {
			String job = JOptionPane.showInputDialog("Podaj kod stanowiska");
			int zmiana = Integer.parseInt(JOptionPane.showInputDialog("Podaj kwotę podwyżki"));
			
			String sql = "UPDATE employees SET salary = salary + ? WHERE job_id = ?" ;
			try(PreparedStatement stmt = c.prepareStatement(sql)) {
				stmt.setInt(1, zmiana);
				stmt.setString(2, job);
				int ile = stmt.executeUpdate();
				JOptionPane.showMessageDialog(null, "Zmodyfikowano " + ile + " rekordów");
			}
		} catch (SQLException e) {
			e.printStackTrace();
			JOptionPane.showMessageDialog(null, e, "Błąd", JOptionPane.ERROR_MESSAGE);
		}
	}

}
