Menu
Question Index
...

What will be the output of the following program? Assume the table as show below with name as 'students'.

import java.io.*;
import java.sql.*;
public class DataBase {
    public static void main(String[] args) {
        // Assume that the connection and statement creation code is here
        printStudentDetails(st);
        // Assume that the connection and statement closing and exception handling code is here
    }
    private static void printStudentDetails(Statement st) throws SQLException, IOException {
        ResultSet resultSet = st.executeQuery("select roll_number, display_name, branch from students where branch = 'CSE' order by display_name");
        StringBuilder sb = new StringBuilder();
        if (resultSet.next()) {
            sb.append(resultSet.getString("roll_number") + ", " + resultSet.getString("display_name") + ", " + resultSet.getString("branch") + "\n");
        }
        resultSet.close();
        System.out.println(sb);
    }
}
+----------------+---------------+---------+
| roll_number    | display_name  | branch  |
+----------------+---------------+---------+
| 084G1A0516     | Kiran         | CSE     |
| 084G1A0532     | Neelima       | CSE     |
| 084G1A0511     | Gowthami      | CSE     |
| 084G1A1217     | Kranthi       | INF     |
| 084G1A0560     | Vishwanath    | CSE     |
| 084G1A0211     | Neelima       | EEE     |
| 084G1A0401     | Ashok         | ECE     |
+----------------+---------------+---------+


084G1A0516, Kiran, CSE
084G1A0532, Neelima, CSE
084G1A0511, Gowthami, CSE
084G1A0560, Vishwanath, CSE
084G1A0511, Gowthami, CSE
084G1A0516, Kiran, CSE
084G1A0532, Neelima, CSE
084G1A0560, Vishwanath, CSE
084G1A0401, Ashok, ECE
084G1A0511, Gowthami, CSE
084G1A0516, Kiran, CSE
084G1A1217, Kranthi, INF
084G1A0532, Neelima, CSE
084G1A0211, Neelima, EEE
084G1A0560, Vishwanath, CSE
Some other output
Compilation Error or Runtime Error

Doubts

Problems

Topic: Other Advanced Topics In Java

Read this topic
Take test on this topic

0
Wrong
Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App