Untitled
unknown
plain_text
3 years ago
818 B
3
Indexable
public static String passedOutStudentsCount(int passout_year) {
String dbURL = "jdbc:mysql://localhost/ri_db";
String username = "test";
String password = "test123";
String sql = "SELECT COUNT(*) FROM OFFICE WHERE year = " + passout_year;
String output = "";
try (Connection conn = DriverManager.getConnection(dbURL, username, password);
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery(sql)) {
rs.next();
int count = rs.getInt(1);
output = "Number of students passed out in " + passout_year + ": " + count;
} catch (SQLException e) {
e.printStackTrace();
}
return output;
}Editor is loading...