Savitribai Phule Pune University T.Y.B.B.A.(C.A.) Advanced Java Practical Slip 27 Answers


A) Write a JSP script to accept the details of Teacher (TID, TName, Desg, Subject ,

Qualification) and display it on the browser. Use appropriate controls for accepting

data.

Answer :

<%@ page language="java" %>
<html>
<head>
  <title>Teacher Details Example</title>
</head>
<body>
  <h1>Teacher Details Example</h1>

  <form method="post">
    TID: <input type="text" name="tid"><br><br>
    TName: <input type="text" name="tname"><br><br>
    Desg: <input type="text" name="desg"><br><br>
    Subject: <input type="text" name="subject"><br><br>
    Qualification: <input type="text" name="qualification"><br><br>
    <input type="submit" value="Submit">
  </form>

  <br><br>

  <%
    String tid = request.getParameter("tid");
    String tname = request.getParameter("tname");
    String desg = request.getParameter("desg");
    String subject = request.getParameter("subject");
    String qualification = request.getParameter("qualification");

    if (tid != null && !tid.isEmpty() && tname != null && !tname.isEmpty() &&
        desg != null && !desg.isEmpty() && subject != null && !subject.isEmpty() &&
        qualification != null && !qualification.isEmpty()) {
      out.println("<h3>Teacher Details:</h3>");
      out.println("TID: " + tid + "<br>");
      out.println("TName: " + tname + "<br>");
      out.println("Desg: " + desg + "<br>");
      out.println("Subject: " + subject + "<br>");
      out.println("Qualification: " + qualification + "<br>");
    }
  %>

</body>
</html>

Output :

 

B) Write a Java Program for the implementation of scrollable ResultSet. Assume

Teacher table with attributes (TID, TName, Salary, Subject) is already created.

Answer :

import java.sql.*;

public class ScrollableResultSetExample {

  public static void main(String[] args) {

    try {
      // Connect to database
      Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/mydatabase", "username", "password");

      // Create statement with scrollable ResultSet
      Statement stmt = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
      ResultSet rs = stmt.executeQuery("SELECT * FROM Teacher");

      // Move to last row
      rs.last();

      // Get row count
      int rowCount = rs.getRow();

      System.out.println("Total number of rows: " + rowCount);

      // Move to first row
      rs.first();

      // Print all rows
      while (rs.next()) {
        System.out.println("TID: " + rs.getInt("TID") +
                           ", TName: " + rs.getString("TName") +
                           ", Salary: " + rs.getDouble("Salary") +
                           ", Subject: " + rs.getString("Subject"));
      }

      // Move to previous row
      rs.previous();

      // Print the data of the previous row
      System.out.println("Previous Row Data: TID=" + rs.getInt("TID") +
                         ", TName=" + rs.getString("TName") +
                         ", Salary=" + rs.getDouble("Salary") +
                         ", Subject=" + rs.getString("Subject"));

      // Move to next row
      rs.next();

      // Print the data of the next row
      System.out.println("Next Row Data: TID=" + rs.getInt("TID") +
                         ", TName=" + rs.getString("TName") +
                         ", Salary=" + rs.getDouble("Salary") +
                         ", Subject=" + rs.getString("Subject"));

      // Move to first row again
      rs.first();

      // Close ResultSet, statement, and connection
      rs.close();
      stmt.close();
      conn.close();

    } catch (SQLException e) {
      e.printStackTrace();
    }

  }

}

Output :


Savitribai Phule Pune University T.Y.B.B.A.(C.A.) Advanced Java Practical Slip 27 Answers Savitribai Phule Pune University T.Y.B.B.A.(C.A.) Advanced Java Practical Slip 27 Answers Reviewed by technical_saurabh on December 15, 2022 Rating: 5

No comments:

Powered by Blogger.