Q.1.
Advanced Java:
A)
Write a java program to count the number of records in a table.
Answer :
import java.io.*;
import java.sql.*;
class Slip12A {
public static void main(String args[]) throws Exception {
Statement stmt;
ResultSet rs;
int cnt = 0;
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/bcadb", "root", "");
stmt = con.createStatement();
rs = stmt.executeQuery("select * from
student");
while (rs.next()) {
cnt++;
}
System.out.println("Total number of records in table is :
" + cnt);
con.close();
}
}
B)
Write a program in java which will show lifecycle (creation, sleep, and dead)
of a
thread.
Program should print randomly the name of thread and value of sleep time. The
name
of the thread should be hard coded through constructor. The sleep time of a thread
will
be a random integer in the range 0 to 4999.
Answer :
No comments:
Post a Comment