Q.1.
Advanced Java:
A)
Write a Java Program to display all the employee names whose initial character
of a
name is ‘A’.
Answer :
import java.io.*;
import java.sql.*;
class Slip8A {
public static void main(String args[]) throws Exception {
Statement stmt;
ResultSet rs;
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/bcadb", "root", "");
stmt = con.createStatement();
rs = stmt.executeQuery("select ename from
emp where ename like 'A%'");
System.out.println("<<<<Employee
Name>>>>>");
System.out.println("==================");
while (rs.next()) {
System.out.println(rs.getString(1));
}
con.close();
}
}
B)
Write a java program in multithreading using applet for Digital watch.
Answer :
import java.applet.*;
import java.awt.*;
import java.util.*;
import java.text.*;
public class Slip8B extends Applet implements Runnable {
Thread t;
String str;
public void start() {
t = new Thread(this);
t.start();
}
public void run() {
try {
while (true) {
Date date = new Date();
SimpleDateFormat Nowtime = new SimpleDateFormat("hh:mm:ss");
str = Nowtime.format(date);
repaint();
t.sleep(1000);
}
} catch (Exception e) {
}
}
public void paint(Graphics g) {
g.drawString(str, 120, 100);
}
}
/*
* <applet code="Slip8B.class"
width="300" height="300">
* </applet>
*/
No comments:
Post a Comment