package bazy.sqlite;

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

import javax.swing.JOptionPane;

public class Podwyzka {

	public static void main(String[] args) {
		String jobId = JOptionPane.showInputDialog("Podaj id stanowiska:");
		int podwyzka = Integer.parseInt(JOptionPane.showInputDialog("Podaj kwotę podwyżki:"));
		
		final String url = "jdbc:sqlite:hr.db";
		final String sql = "UPDATE employees SET salary = salary + ? WHERE job_id = ?";

		try (Connection c = DriverManager.getConnection(url)) {
			try (PreparedStatement stmt = c.prepareStatement(sql)) {
				stmt.setInt(1, podwyzka);
				stmt.setString(2, jobId);
				
				int ile = stmt.executeUpdate();  // właściwe polecenie dla INSERT, UPDATE i DELETE
				
				System.out.println("Zmodyfikowano " + ile + " rekordów.");
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}

}
