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

 



Q.1. Advanced Java:

A) Write a java program to display name of currently executing Thread in

multithreading.

Answer :

public class Slip13A {

    public static void main(String[] args) {

        Thread t = Thread.currentThread();

        System.out.println("Thread Name is : " + t.getName());

    }

}


B) Write a JSP program to display the details of College (CollegeID, Coll_Name,

Address) in tabular form on browser.

Answer :

<%@page import="java.sql.*"%>
<html>
<head>
<title>College Details</title>
</head>
<body>
<h1>College Details</h1>
<table border="1">
<tr>
<th>College ID</th>
<th>College Name</th>
<th>Address</th>
</tr>
<%
try {
    // Load the JDBC driver and establish a connection to the database
    Class.forName("com.mysql.jdbc.Driver");
    Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/mydb", "root", "password");

    // Execute a SELECT query to retrieve the college details
    Statement stmt = con.createStatement();
    ResultSet rs = stmt.executeQuery("SELECT CollegeID, Coll_Name, Address FROM College");

    // Loop through the result set and display the college details in the table
    while (rs.next()) {
        %>
        <tr>
        <td><%= rs.getString("CollegeID") %></td>
        <td><%= rs.getString("Coll_Name") %></td>
        <td><%= rs.getString("Address") %></td>
        </tr>
        <%
    }

    // Clean up resources
    rs.close();
    stmt.close();
    con.close();
} catch (Exception e) {
    out.println("Error: " + e.getMessage());
}
%>
</table>
</body>
</html>

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

No comments:

Powered by Blogger.