QN048. Write a program to display all record of database table.
1. Objective
To
2. Theory
3. Source Code
      import java.sql.*; 
      class JDBC48{
        public static void main(String[] args){
          try{
            Class.forName("com.mysql.cj.jdbc.Driver");
            String url = "jdbc:mysql://localhost:3306/bca_third_2020?serverTimezone=UTC";
            String un = "root";
            String pw = "";
            Connection cn = DriverManager.getConnection(url,un,pw);
            display(cn);
          }catch(Exception e){
            System.out.println(e);
          }
        }
         
 
      private static void display(Connection cn) throws SQLException {
          Statement stat = cn.createStatement(); // statement create
          String query = "select * from student";
          System.out.println("Reading records...");
          ResultSet rs = stat.executeQuery(query); // execute query
          while(rs.next()) {
            System.out.print("Roll NO: "+rs.getString("roll_no"));
            System.out.print(" Name: "+rs.getString("name"));
            System.out.print(" Course: "+rs.getString("course"));
            System.out.println("\n");
          }
          
        }
      }
    
    4. Output
    Reading records... 
    Roll No: 1 Name: Sajan Course: BCA 
    Roll No: 2 Name: Gopal Course: BCA 
    Roll No: 3 Name: Srijana Course: BCA 
    Roll No: 4 Name: Hari Course: BCA 
  
    
5. Conclusion
In this way, I would like to conclude that, by using this program we can display all record of database table.