Created
May 31, 2025 05:28
-
-
Save MahraibFatima/71cd0479f7479c0dd617bb7dd056bfd9 to your computer and use it in GitHub Desktop.
showSalaries method
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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