Skip to content

Instantly share code, notes, and snippets.

@MahraibFatima
Created May 31, 2025 05:28
Show Gist options
  • Save MahraibFatima/71cd0479f7479c0dd617bb7dd056bfd9 to your computer and use it in GitHub Desktop.
Save MahraibFatima/71cd0479f7479c0dd617bb7dd056bfd9 to your computer and use it in GitHub Desktop.
showSalaries method
public static void showSalaries(Connection conn, String dept) {
String sql = "SELECT name, salary FROM employees WHERE department = ?";
try (PreparedStatement stmt = conn.prepareStatement(sql)) {
stmt.setString(1, dept);
ResultSet rs = stmt.executeQuery();
while (rs.next()) {
String name = rs.getString("name");
double salary = rs.getDouble("salary");
System.out.println(name + " - " + salary);
}
} catch (SQLException e) {
e.printStackTrace();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment