TYBBA-CA Advance Java LAB BOOK-1
TYBBA-CA Advance Java LAB BOOK-1
Preface:
For the effective execution of Advance Java practical, this lab manual has
been prepared. It contains 10 theory questions of programming and 40
Practical questions.
This lab book will be considering as Journal for final practical exam.
Prepared by:
Reviewed by:
2
Index
21 Question 21
22 Question 22
23 Question 23
24 Question 24
25 Question 25
26 Question 26
27 Question 27
28 Question 28
29 Question 29
30 Question 30
31 Question 31
32 Question 32
33 Question 33
34 Question 34
35 Question 35
36 Question 36
37 Question 37
38 Question 38
39 Question 39
40 Question 40
Head of Department:
Date:
4
/*Question 1:
Write a java program to accept the start and end number from user in the two text field and on
click of the start button, display all the numbers on the command prompt. Each number must
be displayed after the specific time.
*/
import java.io.*;
import java.lang.*;
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
b1=new Button("START");
b2=new Button("STOP");
add(l1);
add(t1);
5
add(l2);
add(t2);
add(b1);
add(b2);
setSize(400,400);
setVisible(true);
b1.addActionListener(this);
b2.addActionListener(this);
}
public void actionPerformed(ActionEvent ae)
{
Object ob=ae.getSource();
if(ob==b1)
{
t.start();
}
else
{
if(ob==b2)
{
t.stop();
}
}
}
public void run()
{
try
{
sno=Integer.parseInt(t1.getText());
eno=Integer.parseInt(t2.getText());
for(i=sno;i<=eno;i++)
{
6
System.out.println("\n\t\t"+i);
t.sleep(2000);
}
}
catch(Exception e)
{
System.out.println(e);
}
}
}
/*Question 2:
Write a Java program to accept the start and end number in the two text field and on click of
the start button, display all the even numbers in the text area after every two seconds and on
click of the stop button, stop displaying numbers.
*/
import java.io.*;
import java.lang.*;
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
7
l1=new Label("Enter the Start Number :: ");
l2=new Label("Enter the End Number :: ");
l3=new Label("Result :: ");
}
public void start()
{
t1=new TextField(30);
t2=new TextField(30);
ta=new TextArea(10,10);
b1=new Button("START");
b2=new Button("STOP");
add(l1);
add(t1);
add(l2);
add(t2);
add(l3);
add(ta);
add(b1);
add(b2);
setSize(400,400);
setVisible(true);
b1.addActionListener(this);
b2.addActionListener(this);
}
public void actionPerformed(ActionEvent ae)
{
Object ob=ae.getSource();
if(ob==b1)
{
t.start();
8
}
else
{
if(ob==b2)
{
t.stop();
}
}
}
public void run()
{
try
{
sno=Integer.parseInt(t1.getText());
eno=Integer.parseInt(t2.getText());
for(i=sno;i<=eno;i++)
{
if(i%2==0)
{
ta.append("\n"+i);
t.sleep(2000);
}
}
}
catch(Exception e)
{
System.out.println(e);
}
}
}
9
/*Question 3:
Write a Java program to create an applet frame that consists of two buttons and on click of the
start button, demonstrate traffic signal
*/
import java.io.*;
import java.lang.*;
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
Boolean red,yellow,green;
b1=new Button("START");
b2=new Button("STOP");
add(b1);
add(b2);
setSize(400,400);
setVisible(true);
b1.addActionListener(this);
10
b2.addActionListener(this);
}
public void actionPerformed(ActionEvent ae)
{
Object ob=ae.getSource();
if(ob==b1)
{
t.start();
}
else
{
if(ob==b2)
{
t.stop();
}
}
}
public void run()
{
try
{
while(true)
{
if(red==true)
{
red=false;
yellow=true;
green=false;
}
else
{
if(yellow==true)
{
yellow=false;
red=false;
green=true;
}
11
else
{
if(green==true)
{
green=false;
red=true;
yellow=false;
}
}
}
repaint();
t.sleep(1000);
}
}
catch(Exception e)
{
System.out.println(e);
}
}
public void paint(Graphics g)
{
if(red==true)
{
g.setColor(Color.RED);
g.fillOval(300,100,100,100);
}
else
{
if(yellow==true)
{
g.setColor(Color.YELLOW);
g.fillOval(300,200,100,100);
}
else
{
if(green==true)
{
g.setColor(Color.GREEN);
12
g.fillOval(300,300,100,100);
}
}
}
}
}
/*Question 4:
Write a Java program to create an applet frame that consist of two buttons and on click of the
start button, change the background color of the frame in red, blue and green color and on click
of the stop button, stop changing color
*/
import java.io.*;
import java.lang.*;
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
b1=new Button("START");
b2=new Button("STOP");
}
public void start()
{
add(b1);
add(b2);
setSize(400,400);
setVisible(true);
13
b1.addActionListener(this);
b2.addActionListener(this);
}
public void actionPerformed(ActionEvent ae)
{
Object ob=ae.getSource();
if(ob==b1)
{
t.start();
}
else
{
if(ob==b2)
{
t.stop();
}
}
}
public void run()
{
try
{
while(true)
{
setBackground(Color.RED);
t.sleep(200);
setBackground(Color.BLUE);
t.sleep(200);
setBackground(Color.GREEN);
t.sleep(200);
}
}
catch(Exception e)
{
System.out.println(e);
14
}
}
}
/* Question 5:
Write a Java program to create an applet frame that consists of two buttons namely OK and
CACNEL and on click of the OK button, toggle the names on the two buttons.
(Swap the name of the two buttons) and on click of the CANCEL button, stop swapping names
*/
import java.io.*;
import java.lang.*;
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
}
public void start()
{
b1=new Button(" OK ");
b2=new Button(" CACNEL");
add(b1);
add(b2);
setSize(400,400);
setVisible(true);
15
b1.addActionListener(this);
b2.addActionListener(this);
}
public void actionPerformed(ActionEvent ae)
{
Object ob=ae.getSource();
if(ob==b1)
{
t.start();
}
else
{
if(ob==b2)
{
t.stop();
}
}
}
public void run()
{
try
{
while(true)
{
s1=b1.getLabel();
s2=b2.getLabel();
b1.setLabel(s2 );
b2.setLabel(s1);
t.sleep(1000);
}
}
catch(Exception e)
{
System.out.println(e);
}
16
}
}
/* Question 6:
Write a Java program to create an applet frame that consists of two buttons and on click of the
start button, blink both the buttons and on click of the stop button, stop blinking buttons.
*/
import java.io.*;
import java.lang.*;
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
setSize(400,400);
setVisible(true);
b1.addActionListener(this);
b2.addActionListener(this);
}
public void actionPerformed(ActionEvent ae)
{
17
Object ob=ae.getSource();
if(ob==b1)
{
t.start();
}
else
{
if(ob==b2)
{
t.stop();
}
}
}
public void run()
{
try
{
while(true)
{
b1.setVisible(true);
t.sleep(200);
b1.setVisible(false);
t.sleep(200);
b2.setVisible(true);
t.sleep(200);
b2.setVisible(false);
t.sleep(200);
}
}
catch(Exception e)
{
System.out.println(e);
}
}
18
}
Question 7:
Write a Java program to create an applet frame that consists of two buttons and on click of the
start button, rotate the name Indira from left to right. (Use substring () method)
/* Question 8:
Write a java program to create an applet frame that consist of two buttons start and stop and
on click of the start button, demonstrate the CAR RACE
*/
import java.io.*;
import java.lang.*;
import java.util.*;
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
19
add(b1);
add(b2);
add(l1);
add(l2);
setSize(600, 300);
setVisible(true);
b1.addActionListener(this);
b2.addActionListener(this);
}
public void actionPerformed(ActionEvent ae)
{
Object ob = ae.getSource();
if (ob == b1)
{
t.start();
}
else if (ob == b2)
{
t.stop();
}
}
20
if (x == 500)
{
x = 0;
}
}
}
}
catch (Exception e)
{
System.out.println(e);
}
}
}
/* Question 9:
Write a java program to create an applet frame that consists of two buttons start and stop and
on click of the start button, move the ball from top to bottom
*/
import java.io.*;
import java.lang.*;
import java.util.*;
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
Button b1,b2;
int y = 0;
boolean movingDown = false;
21
public void start()
{
b1=new Button("START");
b2=new Button("STOP");
add(b1);
add(b2);
setSize(500,500);
setVisible(true);
b1.addActionListener(this);
b2.addActionListener(this);
}
public void actionPerformed(ActionEvent ae)
{
Object ob=ae.getSource();
if(ob==b1)
{
t.start();
}
else
{
if(ob==b2)
{
t.stop();
}
}
}
public void run()
{
try
{
while(true)
{
if (movingDown)
22
{
y += 5;
if (y >= getHeight() - 100)
{
movingDown = false;
}
}
else
{
y -= 5;
if (y <= 0)
{
movingDown = true;
}
}
repaint();
Thread.sleep(50);
}
}
catch (Exception e)
{
System.out.println(e);
}
}
public void paint(Graphics g)
{
g.setColor(Color.BLUE);
g.fillOval(100, y, 100, 100);
}
}
/* Question 10:
Write a java program to create an applet frame that consists of two buttons start and stop and
on click of the start button, move the ball from bottom to top
*/
import java.io.*;
import java.lang.*;
23
import java.util.*;
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
add(b1);
add(b2);
setSize(500,500);
setVisible(true);
b1.addActionListener(this);
b2.addActionListener(this);
}
public void actionPerformed(ActionEvent ae)
{
Object ob=ae.getSource();
if(ob==b1)
{
t.start();
24
}
else
{
if(ob==b2)
{
t.stop();
}
}
}
public void run()
{
try
{
while(true)
{
if (movingUp)
{
y -= 5;
if (y <= 0)
{
movingUp = false;
}
}
else
{
y += 5;
if (y >= getHeight() - 100)
{
movingUp = true;
}
}
repaint();
t.sleep(50);
}
}
catch (Exception e)
{
25
System.out.println(e);
}
}
public void paint(Graphics g) {
g.setColor(Color.YELLOW);
g.fillOval(100, y, 100, 100);
}
}
/* Question 11:
Write a java program to create an applet frame that consists of two buttons start and stop and
on click of the start button, move the ball from top to bottom
*/
import java.io.*;
import java.lang.*;
import java.util.*;
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
Button b1,b2;
int y = 0;
boolean movingDown = false;
26
add(b1);
add(b2);
setSize(500,500);
setVisible(true);
b1.addActionListener(this);
b2.addActionListener(this);
}
public void actionPerformed(ActionEvent ae)
{
Object ob=ae.getSource();
if(ob==b1)
{
t.start();
}
else
{
if(ob==b2)
{
t.stop();
}
}
}
public void run()
{
try
{
while(true)
{
if (movingDown)
{
y += 5;
if (y >= getHeight() - 100)
{
movingDown = false;
27
}
}
else
{
y -= 5;
if (y <= 0)
{
movingDown = true;
}
}
repaint();
Thread.sleep(50);
}
}
catch (Exception e)
{
System.out.println(e);
}
}
public void paint(Graphics g)
{
g.setColor(Color.BLUE);
g.fillOval(100, y, 100, 100);
}
}
/* Question 12:
28
Write a java program to create an applet frame that consists of two buttons start and stop and
on click of the start button, demonstrate the bouncing ball where the ball should change color
on each bounce. (Use Random class)
*/
import java.io.*;
import java.lang.*;
import java.util.*;
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
Button b1,b2;
int y=0;
int a=0;
add(b1);
add(b2);
setSize(500,500);
setVisible(true);
b1.addActionListener(this);
b2.addActionListener(this);
29
public void actionPerformed(ActionEvent ae)
{
Object ob=ae.getSource();
if(ob==b1)
{
t.start();
}
else
{
if(ob==b2)
{
t.stop();
}
}
}
public void run()
{
try
{
while(true)
{
if(y<=850 && a==0)
{
setBackground(Color.ORANGE);
y=y+10;
repaint();
t.sleep(50);
if(y==850)
{
a=1;
}
}
else
{
if(y>=0 && a==1)
{
30
setBackground(Color.BLACK);
y=y-10;
repaint();
t.sleep(50);
}
if(y==0)
{
a=0;
}
}
}
}
catch(Exception e)
{
System.out.println(e);
}
}
public void paint(Graphics g)
{
Random r=new Random();
int a1=r.nextInt(150);
int a2=r.nextInt(200);
int a3=r.nextInt(100);
g.setColor(c);
g.fillOval(100,y,100,100);
}
}
Question 13:
Write a java program to create an applet frame that consists of two buttons start and stop and
31
on click of the start button, rotate the name iccs in four directions
Eg:
import java.io.*;
import java.lang.*;
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
{
Thread t;
Button b1,b2;
Label l1;
int d=0;
int x=0;
int y;
x=0;
y=200;
l1=new Label("iccs");
l1.setBounds(x,y,100,100);
b1=new Button("START");
32
b2=new Button("STOP");
add(b1);
add(b2);
add(l1);
setSize(500,500);
setVisible(true);
b1.addActionListener(this);
b2.addActionListener(this);
}
public void actionPerformed(ActionEvent ae)
{
Object ob=ae.getSource();
if(ob==b1)
{
t.start();
}
else
{
if(ob==b2)
{
t.stop();
}
}
}
public void run()
{
try
{
while(true)
{
if(x<=200 && y>=0 && d==0)
{
33
x=x+10;
y=y-10;
l1.setBounds(x,y,100,100);
t.sleep(100);
}
else
{
if(x<=400 && y<=200)
{
x=x+10;
y=y+10;
l1.setBounds(x,y,100,100);
t.sleep(100);
d=1;
}
else
{
if(x>=200 && y<=400)
{
x=x-10;
y=y+10;
l1.setBounds(x,y,100,100);
t.sleep(100);
}
else
{
if(x>=0 && y>=200 && d==1)
{
x=x-10;
y=y-10;
l1.setBounds(x,y,100,100);
t.sleep(100);
}
else
{
d=0;
}
}
34
}
}
}
}
catch(Exception e)
{
System.out.println(e);
}
}
}
/* Question 14:
Write a java program to create an applet frame that consists of two buttons start and stop and
on click of the start button, move the string on the frame from right to left
*/
import java.io.*;
import java.lang.*;
import java.util.*;
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
l1 = new Label("ICCS");
35
add(b1);
add(b2);
add(l1);
setSize(600, 300);
setVisible(true);
b1.addActionListener(this);
b2.addActionListener(this);
}
public void actionPerformed(ActionEvent ae)
{
Object ob = ae.getSource();
if (ob == b1)
{
t.start();
}
else if (ob == b2)
{
t.stop();
}
}
36
x = 500;
}
}
}
}
catch (Exception e)
{
System.out.println(e);
}
}
}
/* Question 15:
Write a java program to display all the database on the command prompt using JDBC statement
*/
import java.io.*;
import java.lang.*;
import java.sql.*;
class abc
{
Connection con;
Statement stmt;
ResultSet rs;
String sql;
public abc()
{
try
{
Class.forName("net.ucanaccess.jdbc.UcanaccessDriver");
con=DriverManager.getConnection("jdbc:ucanaccess://tydb.accdb");
}
catch(Exception e)
{
System.out.println(e);
}
}
37
public void display()
{
try
{
sql="select * from tytable";
stmt=con.createStatement();
rs=stmt.executeQuery(sql);
if(rs.next())
{
System.out.println("\n\tRollNO\tNAME\tPER\tCOURSE");
do
{
System.out.print("\t"+rs.getInt("rollno")+"\
t"+rs.getString("name")+"\t"+rs.getInt("percentage")+"\t"+rs.getString("course"));
System.out.println("\n\n");
}while(rs.next());
}
else
{
System.out.println("No Data Found");
}
}
catch(Exception e)
{
System.out.println(e);
}
}
}
class Q15
{
public static void main(String args[])
{
abc x=new abc();
x.display();
}
}
38
/* Question 16:
Write a java program to accept the rollno from user on the command prompt and display all
the database of that student only on the command prompt using JDBC statement
*/
import java.io.*;
import java.lang.*;
import java.sql.*;
class abc
{
Connection con;
Statement stmt;
ResultSet rs;
String sql;
int r=0;
public abc()
{
try
{
Class.forName("net.ucanaccess.jdbc.UcanaccessDriver");
con=DriverManager.getConnection("jdbc:ucanaccess://tydb.accdb");
}
catch(Exception e)
{
System.out.println(e);
}
}
39
sql="select * from tytable where rollno = "+r;
stmt=con.createStatement();
rs=stmt.executeQuery(sql);
if(rs.next())
{
System.out.println("\n\tRollNO\tNAME\tPER\tCOURSE");
do
{
System.out.print("\t"+rs.getInt("rollno")+"\
t"+rs.getString("name")+"\t"+rs.getInt("percentage")+"\t"+rs.getString("course"));
System.out.println("\n\n");
}while(rs.next());
}
else
{
System.out.println("No Data Found");
}
}
catch(Exception e)
{
System.out.println(e);
}
}
}
class Q16
{
public static void main(String args[])
{
abc x=new abc();
x.display();
}
}
40
/* Question 17:
Write a java program to accept the name from user on the command prompt and display all the
database of that student only on the command prompt using JDBC statement
*/
import java.io.*;
import java.lang.*;
import java.sql.*;
class abc
{
Connection con;
Statement stmt;
ResultSet rs;
String sql;
String nm;
public abc()
{
try
{
Class.forName("net.ucanaccess.jdbc.UcanaccessDriver");
con=DriverManager.getConnection("jdbc:ucanaccess://tydb.accdb");
}
catch(Exception e)
{
System.out.println(e);
}
}
public void display()
{
try
{
BufferedReader br=new BufferedReader(new
InputStreamReader(System.in));
System.out.print("Enter the Student Name :: ");
nm=br.readLine();
41
sql="select * from tytable where name='"+nm+"'";
stmt=con.createStatement();
rs=stmt.executeQuery(sql);
if(rs.next())
{
System.out.println("\n\tRollNO\tNAME\tPER\tCOURSE");
do
{
System.out.print("\t"+rs.getInt("rollno")+"\
t"+rs.getString("name")+"\t"+rs.getInt("percentage")+"\t"+rs.getString("course"));
System.out.println("\n\n");
}while(rs.next());
}
else
{
System.out.println("No Data Found");
}
}
catch(Exception e)
{
System.out.println(e);
}
}
}
class Q17
{
public static void main(String args[])
{
abc x=new abc();
x.display();
}
}
/*Question 18:
Write a java program to accept the rollno and name from user and insert the record into the
42
database and also display the updated record on the command prompt
*/
import java.io.*;
import java.lang.*;
import java.sql.*;
class xyz
{
Connection con;
Statement stmt;
ResultSet rs;
String sql;
String nm;
int i=0;
int rn=0;
public xyz()
{
try
{
Class.forName("net.ucanaccess.jdbc.UcanaccessDriver");
con=DriverManager.getConnection("jdbc:ucanaccess://tybcadb.accdb");
}
catch(Exception e)
{
System.out.println(e);
}
}
public void insert()
{
try
{
BufferedReader br=new BufferedReader(new
InputStreamReader(System.in));
43
System.out.print("Enter the Name :: ");
nm=br.readLine();
if(i>0)
{
System.out.println("\n Data Inserted. ");
}
else
{
System.out.println("\n Data Not Inserted. ");
}
}
catch(Exception e)
{
System.out.println(e);
}
}
public void display()
{
try
{
sql="select * from tybcatable";
stmt=con.createStatement();
rs=stmt.executeQuery(sql);
if(rs.next())
{
System.out.println("\n\tRollNO\tNAME");
do
{
System.out.print("\t"+rs.getInt("rollno")+"\
t"+rs.getString("name"));
System.out.println("\n\n");
44
}while(rs.next());
}
else
{
System.out.println("No Data Found");
}
}
catch(Exception e)
{
System.out.println(e);
}
}
}
class Q18
{
public static void main(String args[])
{
xyz x=new xyz();
x.insert();
x.display();
}
}
/* Question 19:
Write a java program to accept the rollno from user and delete the record of that student only
and also display the updated record on the command prompt
*/
import java.io.*;
import java.lang.*;
import java.sql.*;
class xyz
{
Connection con;
Statement stmt;
ResultSet rs;
String sql;
int i=0;
45
int rn=0;
public xyz()
{
try
{
Class.forName("net.ucanaccess.jdbc.UcanaccessDriver");
con=DriverManager.getConnection("jdbc:ucanaccess://tybcadb.accdb");
}
catch(Exception e)
{
System.out.println(e);
}
}
public void delete()
{
try
{
BufferedReader br=new BufferedReader(new
InputStreamReader(System.in));
if(i>0)
{
System.out.println("\n Data Deleted. ");
}
else
{
System.out.println("\n Data Not Deleted. ");
}
}
46
catch(Exception e)
{
System.out.println(e);
}
}
public void display()
{
try
{
sql="select * from tybcatable";
stmt=con.createStatement();
rs=stmt.executeQuery(sql);
if(rs.next())
{
System.out.println("\n\tRollNO\tNAME");
do
{
System.out.print("\t"+rs.getInt("rollno")+"\
t"+rs.getString("name"));
System.out.println("\n\n");
}while(rs.next());
}
else
{
System.out.println("No Data Found");
}
}
catch(Exception e)
{
System.out.println(e);
}
}
}
class Q19
{
public static void main(String args[])
{
47
xyz x=new xyz();
x.delete();
x.display();
}
}
/*
Q19 and Q 20 is same.
Question 20:
Write a java program to accept the name from user and delete the record of that student only
and also display the updated record on the command prompt
*/
import java.io.*;
import java.lang.*;
import java.sql.*;
class xyz
{
Connection con;
Statement stmt;
ResultSet rs;
String sql;
int i=0;
int rn=0;
public xyz()
{
try
{
Class.forName("net.ucanaccess.jdbc.UcanaccessDriver");
con=DriverManager.getConnection("jdbc:ucanaccess://tybcadb.accdb");
}
catch(Exception e)
{
System.out.println(e);
}
}
public void delete()
48
{
try
{
BufferedReader br=new BufferedReader(new
InputStreamReader(System.in));
if(i>0)
{
System.out.println("\n Data Deleted. ");
}
else
{
System.out.println("\n Data Not Deleted. ");
}
}
catch(Exception e)
{
System.out.println(e);
}
}
public void display()
{
try
{
sql="select * from tybcatable";
stmt=con.createStatement();
rs=stmt.executeQuery(sql);
if(rs.next())
{
System.out.println("\n\tRollNO\tNAME");
49
do
{
System.out.print("\t"+rs.getInt("rollno")+"\
t"+rs.getString("name"));
System.out.println("\n\n");
}while(rs.next());
}
else
{
System.out.println("No Data Found");
}
}
catch(Exception e)
{
System.out.println(e);
}
}
}
class Q20
{
public static void main(String args[])
{
xyz x=new xyz();
x.delete();
x.display();
}
}
/* Question 21:
Write a java program to display the following options to the end user
i. Display the record by rollno
50
ii. Display the record by name
Accept the choice from user and according to the user’s choice, display the output on the
command prompt
*/
import java.io.*;
import java.lang.*;
import java.sql.*;
class abc
{
Connection con;
Statement stmt;
ResultSet rs;
String sql;
String nm;
int ch=0;
int r=0;
public abc()
{
try
{
Class.forName("net.ucanaccess.jdbc.UcanaccessDriver");
con=DriverManager.getConnection("jdbc:ucanaccess://tydb.accdb");
}
catch(Exception e)
{
System.out.println(e);
}
}
51
BufferedReader br=new BufferedReader(new
InputStreamReader(System.in));
switch(ch)
{
case 1:
System.out.print("\nEnter the Roll No :: ");
r=Integer.parseInt(br.readLine());
if(rs.next())
{
System.out.println("\n\tRollNO\tNAME\tPER\tCOURSE");
do
{
System.out.print("\t"+rs.getInt("rollno")+"\
t"+rs.getString("name")+"\t"+rs.getInt("percentage")+"\t"+rs.getString("course"));
System.out.println("\n\n");
}while(rs.next());
}
else
{
System.out.println("No Data Found");
}
break;
case 2:
System.out.print("\nEnter the Student Name :: ");
nm=br.readLine();
52
sql="select * from tytable where name ='"+nm+"'";
stmt=con.createStatement();
rs=stmt.executeQuery(sql);
if(rs.next())
{
System.out.println("\n\tRollNO\tNAME\tPER\tCOURSE");
do
{
System.out.print("\t"+rs.getInt("rollno")+"\
t"+rs.getString("name")+"\t"+rs.getInt("percentage")+"\t"+rs.getString("course"));
System.out.println("\n\n");
}while(rs.next());
}
else
{
System.out.println("No Data Found");
}
break;
default:
System.out.println("Invalid Entry");
}
}
catch(Exception e)
{
System.out.println(e);
}
}
}
class Q21
{
public static void main(String args[])
{
abc x=new abc();
x.display();
53
}
}
/*Question 22:
Write a java program to display the following options to the end user
i. Delete the record by rollno
ii. Delete the record by name
Accept the choice from user and according to the user’s choice, display the output on the
command prompt (Use prepared Statement)
*/
import java.io.*;
import java.lang.*;
import java.sql.*;
class abc
{
Connection con;
PreparedStatement pstmt;
ResultSet rs;
String sql,nm;
int ch=0,rn=0,i=0;
public abc()
{
try
{
Class.forName("net.ucanaccess.jdbc.UcanaccessDriver");
con=DriverManager.getConnection("jdbc:ucanaccess://tybcadb.accdb");
}
catch(Exception e)
{
System.out.println(e);
}
}
public void display()
{
try
{
54
while(true)
{
switch(ch)
{
case 1:
try
{
pstmt=con.prepareStatement("delete * from tybcatable
where rollno=?");
pstmt.setInt(1,rn);
i=pstmt.executeUpdate();
if(i>0)
{
System.out.println("\n Data Deleted. ");
}
else
{
System.out.println("\n Data Not Deleted. ");
}
}
catch(Exception e)
{
55
System.out.println(e);
}
show();
break;
case 2:
try
{
pstmt=con.prepareStatement("delete * from tybcatable
where name=?");
pstmt.setString(1,nm);
i=pstmt.executeUpdate();
if(i>0)
{
System.out.println("\n Data Deleted. ");
}
else
{
System.out.println("\n Data Not Deleted. ");
}
}
catch(Exception e)
{
System.out.println(e);
}
show();
break;
case 3:
System.out.println("Exiting program.");
return;
default:
System.out.println("\nInvalid Entry\n");
56
}
}
}
catch(Exception e)
{
System.out.println(e);
}
}
public void show()
{
try
{
pstmt=con.prepareStatement("select * from tybcatable");
rs=pstmt.executeQuery();
if(rs.next())
{
System.out.println("\n\tRollNO\tNAME\n");
do
{
System.out.print("\t"+rs.getInt("rollno")+"\
t"+rs.getString("name"));
System.out.println("\n\n");
}while(rs.next());
}
else
{
System.out.println("No Data Found");
}
}
catch(Exception e)
{
System.out.println(e);
}
}
}
class Q22
{
57
public static void main(String args[])
{
abc x=new abc();
x.display();
}
}
/* Question 23:
Write a java program to accept the rollno and new name from user and using prepared
statement, update the name according to the rollno given and also display the updated record
on the command prompt
*/
import java.io.*;
import java.lang.*;
import java.sql.*;
class xyz
{
Connection con;
PreparedStatement pstmt;
ResultSet rs;
String sql;
String nm;
int i=0;
int rn=0;
public xyz()
{
try
{
Class.forName("net.ucanaccess.jdbc.UcanaccessDriver");
con=DriverManager.getConnection("jdbc:ucanaccess://tybcadb.accdb");
}
catch(Exception e)
{
System.out.println(e);
}
}
public void update()
58
{
try
{
pstmt=con.prepareStatement("update tybcatable set name=? where rollno=?");
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
pstmt.setString(1,nm);
pstmt.setInt(2,rn);
i=pstmt.executeUpdate();
if(i>0)
{
System.out.println("\n Data Updated. ");
}
else
{
System.out.println("\n Data Not Updated. ");
}
}
catch(Exception e)
{
System.out.println(e);
}
}
public void display()
{
try
{
pstmt=con.prepareStatement("select * from tybcatable");
rs=pstmt.executeQuery();
if(rs.next())
59
{
System.out.println("\n\tRollNO\tNAME");
do
{
System.out.print("\t"+rs.getInt("rollno")+"\t"+rs.getString("name"));
System.out.println("\n\n");
} while(rs.next());
}
else
{
System.out.println("No Data Found");
}
}
catch(Exception e)
{
System.out.println(e);
}
}
}
public class Q23
{
public static void main(String args[])
{
xyz x=new xyz();
x.update();
x.display();
}
}
/* Question 24:
Write a java program to accept the rollno in text field and on click of the display button, display
the record of that student on the command prompt
*/
60
import java.io.*;
import java.lang.*;
import java.awt.*;
import java.awt.event.*;
import java.sql.*;
class abc extends Frame implements ActionListener
{
Panel p;
Button b1;
TextField t1;
Label l1;
Connection con;
Statement stmt;
ResultSet rs;
String sql;
int roll=0;
public abc()
{
p=new Panel();
l1=new Label("Enter any Roll No ::");
t1=new TextField(10);
b1=new Button("Display");
add(p);
p.add(l1);
p.add(t1);
p.add(b1);
setSize(400,400);
setVisible(true);
b1.addActionListener(this);
}
public void actionPerformed(ActionEvent ae)
{
Object ob=ae.getSource();
if(ob==b1)
61
{
try
{
Class.forName("net.ucanaccess.jdbc.UcanaccessDriver");
con=DriverManager.getConnection("jdbc:ucanaccess://tybcadb.accdb");
roll=Integer.parseInt(t1.getText());
if(rs.next())
{
System.out.println("\n\tRollNO\tNAME");
do
{
System.out.print("\t"+rs.getInt("rollno")+"\
t"+rs.getString("name"));
System.out.println("\n\n");
}while(rs.next());
}
else
{
System.out.println("No Data Found");
}
}
catch(Exception e)
{
System.out.println(e);
}
}
}
}
class Q24
{
62
public static void main(String args[])
{
abc x=new abc();
}
}
/*Question 25:
Write a java program to accept the rollno and name in text field and on click of the insert
button, Insert the record inside the database and on click of the display button, display the
updated record on the command prompt
*/
import java.io.*;
import java.lang.*;
import java.awt.*;
import java.awt.event.*;
import java.sql.*;
class abc extends Frame implements ActionListener
{
Panel p;
Button b1,b2,b3;
TextField t1,t2;
Label l1,l2;
Connection con;
Statement stmt;
ResultSet rs;
String sql,nm;
int roll=0,i=0;
public abc()
{
p=new Panel();
l1=new Label("Enter any Roll No::");
l2=new Label("Enter any Name::");
t1=new TextField(10);
t2=new TextField(20);
b1=new Button("INSERT");
b2=new Button("DISPLAY DB");
63
b3=new Button("RESET");
add(p);
p.add(l1);
p.add(t1);
p.add(l2);
p.add(t2);
p.add(b1);
p.add(b2);
p.add(b3);
setSize(400,400);
setVisible(true);
b1.addActionListener(this);
b2.addActionListener(this);
b3.addActionListener(this);
}
public void actionPerformed(ActionEvent ae)
{
Object ob=ae.getSource();
if(ob==b1)
{
try
{
Class.forName("net.ucanaccess.jdbc.UcanaccessDriver");
con=DriverManager.getConnection("jdbc:ucanaccess://tybcadb.accdb");
roll=Integer.parseInt(t1.getText());
nm=t2.getText();
64
if(i>0)
{
System.out.println("Data Inserted.");
}
else
{
System.out.println("Data Not Inserted.");
}
}
catch(Exception e)
{
System.out.println(e);
}
}
else
{
if(ob==b2)
{
try
{
if(rs.next())
{
System.out.println("\n\tRollNO\tNAME");
do
{
System.out.print("\t"+rs.getInt("rollno")+"\
t"+rs.getString("name"));
System.out.println("\n\n");
}while(rs.next());
}
else
{
65
System.out.println("No Data Found");
}
}
catch(Exception e)
{
System.out.println(e);
}
}
else
{
if(ob==b3)
{
t1.setText("");
t1.requestFocus();
t2.setText("");
t2.requestFocus();
}
}
}
}
}
class Q25
{
public static void main(String args[])
{
abc x=new abc();
}
}
/* Question 26:
Write a java program to accept the rollno text field and on click of the delete button, delete the
record of that student from the database and on click of the display button, display the updated
record on the command prompt
*/
66
import java.io.*;
import java.lang.*;
import java.awt.*;
import java.awt.event.*;
import java.sql.*;
class abc extends Frame implements ActionListener
{
Panel p;
Button b1,b2,b3;
TextField t1;
Label l1;
Connection con;
Statement stmt;
ResultSet rs;
String sql;
int roll=0,i=0;
public abc()
{
p=new Panel();
l1=new Label("Enter any Roll No::");
t1=new TextField(10);
b1=new Button("DELETE");
b2=new Button("DISPLAY DB");
b3=new Button("RESET");
add(p);
p.add(l1);
p.add(t1);
p.add(b1);
p.add(b2);
p.add(b3);
setSize(400,400);
setVisible(true);
67
b1.addActionListener(this);
b2.addActionListener(this);
b3.addActionListener(this);
}
public void actionPerformed(ActionEvent ae)
{
Object ob=ae.getSource();
if(ob==b1)
{
try
{
Class.forName("net.ucanaccess.jdbc.UcanaccessDriver");
con=DriverManager.getConnection("jdbc:ucanaccess://tybcadb.accdb");
roll=Integer.parseInt(t1.getText());
if(i>0)
{
System.out.println("Data Deleted.");
}
else
{
System.out.println("Data Not Deleted.");
}
}
catch(Exception e)
{
System.out.println(e);
}
}
else
{
if(ob==b2)
68
{
try
{
if(rs.next())
{
System.out.println("\n\tRollNO\tNAME");
do
{
System.out.print("\t"+rs.getInt("rollno")+"\
t"+rs.getString("name"));
System.out.println("\n\n");
}while(rs.next());
}
else
{
System.out.println("No Data Found");
}
}
catch(Exception e)
{
System.out.println(e);
}
}
else
{
if(ob==b3)
{
t1.setText("");
t1.requestFocus();
}
}
}
69
}
}
class Q26
{
public static void main(String args[])
{
abc x=new abc();
}
}
/* Question 27:
Write a java program to accept the rollno and new name in the text field and on click of the
update button, update the record of that student from the database and on click of the display
button, display the updated record on the command prompt
*/
import java.io.*;
import java.lang.*;
import java.awt.*;
import java.awt.event.*;
import java.sql.*;
class abc extends Frame implements ActionListener
{
Panel p;
Button b1,b2,b3;
TextField t1,t2;
Label l1,l2;
Connection con;
Statement stmt;
ResultSet rs;
String sql,nm;
int roll=0,i=0;
public abc()
{
p=new Panel();
l1=new Label("Enter the Roll No::");
l2=new Label("Enter the New Name::");
70
t1=new TextField(10);
t2=new TextField(20);
b1=new Button("UPDATE");
b2=new Button("DISPLAY DB");
b3=new Button("RESET");
add(p);
p.add(l1);
p.add(t1);
p.add(l2);
p.add(t2);
p.add(b1);
p.add(b2);
p.add(b3);
setSize(400,400);
setVisible(true);
b1.addActionListener(this);
b2.addActionListener(this);
b3.addActionListener(this);
}
public void actionPerformed(ActionEvent ae)
{
Object ob=ae.getSource();
if(ob==b1)
{
try
{
Class.forName("net.ucanaccess.jdbc.UcanaccessDriver");
con=DriverManager.getConnection("jdbc:ucanaccess://tybcadb.accdb");
roll=Integer.parseInt(t1.getText());
nm=t2.getText();
71
sql="update tybcatable set name='"+nm+"' where rollno = "+roll;
stmt=con.createStatement();
i=stmt.executeUpdate(sql);
if(i>0)
{
System.out.println("Data Updated.");
}
else
{
System.out.println("Data Not Updated.");
}
}
catch(Exception e)
{
System.out.println(e);
}
}
else
{
if(ob==b2)
{
try
{
if(rs.next())
{
System.out.println("\n\tRollNO\tNAME");
do
{
System.out.print("\t"+rs.getInt("rollno")+"\
t"+rs.getString("name"));
System.out.println("\n\n");
72
}while(rs.next());
}
else
{
System.out.println("No Data Found");
}
}
catch(Exception e)
{
System.out.println(e);
}
}
else
{
if(ob==b3)
{
t1.setText("");
t1.requestFocus();
t2.setText("");
t2.requestFocus();
}
}
}
}
}
class Q27
{
public static void main(String args[])
{
abc x=new abc();
}
}
/* Question 28:
Write a Java Servlet program to accept the single number of any digit from user on client side
and display the reverse of that number on the web browser
*/
73
import java.io.*;
import java.lang.*;
import javax.servlet.*;
import javax.servlet.http.*;
}
public void doPost(HttpServletRequest req,HttpServletResponse res)throws
ServletException,IOException
{
res.setContentType("text/html");
PrintWriter out = res.getWriter();
no=Integer.parseInt(req.getParameter("txt1"));
74
while (no!=0)
{
int digit=no%10;
rno=rno*10+digit;
no/=10;
}
out.println("<b>Reversed number:: </b>" +rno);
}
}
/* Question 29:
Write a Java Servlet program to accept the single number of any digit from user on client side and
check whether that number is palindrome or not
*/
import java.io.*;
import java.lang.*;
import javax.servlet.*;
import javax.servlet.http.*;
75
out.println("</form>");
out.println("</body>");
out.println("</html>");
}
public void doPost(HttpServletRequest req,HttpServletResponse res)throws
ServletException,IOException
{
res.setContentType("text/html");
PrintWriter out = res.getWriter();
no=Integer.parseInt(req.getParameter("txt1"));
int originalNumber = no;
int reversedNumber = 0;
while (no != 0)
{
int digit = no % 10;
reversedNumber = reversedNumber * 10 + digit;
no /= 10;
}
if (originalNumber == reversedNumber)
{
out.println("<b>" + originalNumber + " is a palindrome number.</b>");
}
else
{
out.println("<b>" + originalNumber + " is not a palindrome number.</b>");
}
}
}
/*Question 30:
Write a Java Servlet program to accept the single number of any digit from user on client
side and check whether that number is Armstrong or not
*/
import java.io.*;
76
import java.lang.*;
import javax.servlet.*;
import javax.servlet.http.*;
}
public void doPost(HttpServletRequest req,HttpServletResponse res)throws
ServletException,IOException
{
res.setContentType("text/html");
PrintWriter out = res.getWriter();
no=Integer.parseInt(req.getParameter("txt1"));
77
while (originalNumber != 0)
{
remainder = originalNumber % 10;
result +=(remainder*remainder*remainder);
originalNumber /= 10;
}
if (result == no)
{
out.println("<b>" + no + " is an Armstrong number.</b>");
}
else
{
out.println("<b>" + no + " is not an Armstrong number.</b>");
}
}
}
/* Question 31:
Write a Java Servlet program to accept user name and password on client side and on the
server side check whether the user name and password match with each other or not
*/
import java.io.*;
import java.lang.*;
import javax.servlet.*;
import javax.servlet.http.*;
78
res.setContentType("text/html");
PrintWriter out = res.getWriter();
out.println("<html>");
out.println("<body>");
out.println("<form method=post action=Q31>");
out.print("<br><br> Enter the Username :: <input type=text name=txt1></input>");
out.print("<br><br> Enter the Passoword :: <input type=text name=txt2></input>");
out.println("<br><br><input type=SUBMIT value=CHECK></input>");
out.println("<input type=RESET value=RESET></input>");
out.println("</form>");
out.println("</body>");
out.println("</html>");
}
public void doPost(HttpServletRequest req,HttpServletResponse res)throws
ServletException,IOException
{
res.setContentType("text/html");
PrintWriter out = res.getWriter();
str1=req.getParameter("txt1");
str2=req.getParameter("txt2");
if(str1.equals(str2))
{
out.println("<b>The Username and Password are Matched.</b>");
}
else
{
out.println("<b>The Username and Password are Not Matched.</b>");
}
}
}
/*Question 32:
Write a Java Servlet program to accept the number of any digit and on click of the DISPLAY button,
display that number in terms of words
(123-one two three)
*/
import java.io.*;
79
import java.lang.*;
import javax.servlet.*;
import javax.servlet.http.*;
}
public void doPost(HttpServletRequest req,HttpServletResponse res)throws
ServletException,IOException
{
res.setContentType("text/html");
PrintWriter out = res.getWriter();
no=Integer.parseInt(req.getParameter("txt1"));
String[] words = {"zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"};
80
}
}
/*Question 33:
Write a Java Servlet program to accept the rollno from user and on click of the DISPLAY Button, display
the record of that student only on the web browser
*/
import java.io.*;
import java.sql.*;
import java.lang.*;
import javax.servlet.*;
import javax.servlet.http.*;
out.println("<html>");
out.println("<body>");
out.println("</form>");
out.println("</body>");
out.println("</html>");
}
public void doPost(HttpServletRequest req,HttpServletResponse res)throws
81
ServletException,IOException
{
res.setContentType("text/html");
PrintWriter out=res.getWriter();
try
{
Class.forName("net.ucanaccess.jdbc.UcanaccessDriver");
con=DriverManager.getConnection("jdbc:ucanaccess://C:/Program Files/Apache
Software Foundation/Tomcat 9.0/webapps/examples/WEB-INF/classes/tydb.accdb");
pstmt.setInt(1,rn);
rs=pstmt.executeQuery();
if (rs.next())
{
out.println("<h4> ROLLNO   NAME<br></h4>");
do
{
out.println(" "+rs.getInt("rollno")+" 
 "+rs.getString("name"));
out.println("<br>");
}while (rs.next());
}
else
{
out.println("\n No data found");
}
}
catch(Exception e)
{
out.println(e);
}
}
}
/* Question 34:
Write a Java Servlet program to accept the rollno and name from user and on click of the
INSERT button, insert the record into the database and on click of DISPLAY Button, display the
updated record on the web browser
*/
82
import java.io.*;
import java.sql.*;
import java.lang.*;
import javax.servlet.*;
import javax.servlet.http.*;
out.println("<html>");
out.println("<body>");
out.println("</form>");
out.println("</body>");
out.println("</html>");
83
}
public void doPost(HttpServletRequest req,HttpServletResponse res)throws
ServletException,IOException
{
res.setContentType("text/html");
PrintWriter out=res.getWriter();
try
{
Class.forName("net.ucanaccess.jdbc.UcanaccessDriver");
con=DriverManager.getConnection("jdbc:ucanaccess://C:/Program
Files/Apache Software Foundation/Tomcat
9.0/webapps/examples/WEB-INF/classes/tydb.accdb");
pstmt.setInt(1,rn);
pstmt.setString(2,nm);
i=pstmt.executeUpdate();
if(i>0)
{
out.println("Record Inserted.");
}
else
{
out.println("Record Not Inserted.");
}
if (rs.next())
{
out.println("<h4> ROLLNO   NAME<br></h4>");
84
do
{
out.println(" "+rs.getInt("rollno")+" 
 "+rs.getString("name"));
out.println("<br>");
}while (rs.next());
}
else
{
out.println("\n No data found");
}
}
catch(Exception e)
{
out.println(e);
}
}
}
/* Question 35:
Write a Java Servlet program to accept the rollno from user and on click of the DELETE button,
delete the record of that student database and on click of DISPLAY Button, display the updated
record on the web browser
*/
import java.io.*;
import java.sql.*;
import java.lang.*;
import javax.servlet.*;
import javax.servlet.http.*;
85
ServletException,IOException
{
res.setContentType("text/html");
PrintWriter out=res.getWriter();
out.println("<html>");
out.println("<body>");
out.println("</form>");
out.println("</body>");
out.println("</html>");
}
public void doPost(HttpServletRequest req,HttpServletResponse res)throws
ServletException,IOException
{
res.setContentType("text/html");
PrintWriter out=res.getWriter();
try
{
Class.forName("net.ucanaccess.jdbc.UcanaccessDriver");
con=DriverManager.getConnection("jdbc:ucanaccess://C:/Program
Files/Apache Software Foundation/Tomcat
9.0/webapps/examples/WEB-INF/classes/tydb.accdb");
i=pstmt.executeUpdate();
if(i>0)
{
out.println("Record Deleted.");
}
else
{
out.println("Record Not Deleted.");
}
86
pstmt=con.prepareStatement("select * from tytable");
rs=pstmt.executeQuery();
if (rs.next())
{
out.println("<h4> ROLLNO   NAME<br></h4>");
do
{
out.println(" "+rs.getInt("rollno")+" 
 "+rs.getString("name"));
out.println("<br>");
}while (rs.next());
}
else
{
out.println("\n No data found");
}
}
catch(Exception e)
{
out.println(e);
}
}
}
Question 36:
Write a Java JSP example to accept the two strings from HTML page and on click of the submit
button, check whether the two strings are same or not. Display the message on the web
browser
Question 37:
Write a Java JSP example to accept the name from user via HTML Page and on click of the
submit button, display the record of that student on the web browser
Question 38:
Write a Java JSP example to accept the rollno name from user via HTML Page and on click of the
insert button, insert the record into the database and display the updated record on the web
browser
87
Question 39:
Write a Java JSP example to accept the rollno from user on the client side and delete the record
of that student on from the database and also display the updated record on the web browser
Question 40:
Write a Java JSP example to display all the records with the initial letter A on click of the display
button.
/*Question 41:
Write a Java program to accept the rollno and new name from user on the client side and on
click of the update button, update the record into the database and also display the updated
record on the web browser
*/
import java.io.*;
import java.sql.*;
import java.lang.*;
import javax.servlet.*;
import javax.servlet.http.*;
88
out.println("<html>");
out.println("<body>");
out.println("</form>");
out.println("</body>");
out.println("</html>");
}
public void doPost(HttpServletRequest req,HttpServletResponse res)throws
ServletException,IOException
{
res.setContentType("text/html");
PrintWriter out=res.getWriter();
try
{
Class.forName("net.ucanaccess.jdbc.UcanaccessDriver");
con=DriverManager.getConnection("jdbc:ucanaccess://C:/Program
Files/Apache Software Foundation/Tomcat
9.0/webapps/examples/WEB-INF/classes/tydb.accdb");
pstmt.setString(1,nm);
pstmt.setInt(2,rn);
i=pstmt.executeUpdate();
if(i>0)
89
{
out.println("Record Updated.");
}
else
{
out.println("Record Not Updated.");
}
if (rs.next())
{
//out.println("<h4> ROLLNO   NAME<br></h4>");
out.println("<html><body><h2>Updated Database:</h2><table
border='1'><tr><th>Roll No</th><th>Name</th></tr>");
do
{
//out.println(" "+rs.getInt("rollno")+" 
 "+rs.getString("name"));
out.println("<tr><td>" + rs.getInt("rollno") + "</td><td>" +
rs.getString("name") + "</td></tr>");
//out.println("<br>");
}while (rs.next());
out.println("</table></body></html>");
}
else
{
out.println("\n No data found");
}
}
catch(Exception e)
{
out.println(e);
}
}
}
90
Question 42:
Write a Java networking program to accept single number from user and send it to server and
on the server side, check whether that number is Armstrong or not
Question 43:
Write a Java networking program to accept name of the file from user on client side and on the
server side check whether that file exists or not. If the file exists then display the content of
that file on the server
Question 44:
Write a Java networking program to accept the rollno from user on the client side and on the
server side, display the record of that student
/*Question 45:
Write a java program to accept the rollno and name from user on the client side and on the
server side, insert the record into the database and also the display the updated record on the
server side
*/
import java.io.*;
import java.sql.*;
import java.lang.*;
import javax.servlet.*;
import javax.servlet.http.*;
91
public void doGet(HttpServletRequest req,HttpServletResponse res)throws
ServletException,IOException
{
res.setContentType("text/html");
PrintWriter out=res.getWriter();
out.println("<html>");
out.println("<body>");
out.println("</form>");
out.println("</body>");
out.println("</html>");
}
public void doPost(HttpServletRequest req,HttpServletResponse res)throws
ServletException,IOException
{
res.setContentType("text/html");
PrintWriter out=res.getWriter();
try
{
Class.forName("net.ucanaccess.jdbc.UcanaccessDriver");
con=DriverManager.getConnection("jdbc:ucanaccess://C:/Program
Files/Apache Software Foundation/Tomcat
9.0/webapps/examples/WEB-INF/classes/tydb.accdb");
92
pstmt.setInt(1,rn);
pstmt.setString(2,nm);
i=pstmt.executeUpdate();
if(i>0)
{
out.println("Record Inserted.");
}
else
{
out.println("Record Not Inserted.");
}
if (rs.next())
{
out.println("<h4> ROLLNO   NAME<br></h4>");
do
{
out.println(" "+rs.getInt("rollno")+" 
 "+rs.getString("name"));
out.println("<br>");
}while (rs.next());
}
else
{
out.println("\n No data found");
}
}
catch(Exception e)
{
out.println(e);
}
}
}
/* Question 46:
93
Write a java program to accept the rollno from user on client side and on the server side, delete
the record from the database and display the updated record on the server
*/
import java.io.*;
import java.sql.*;
import java.lang.*;
import javax.servlet.*;
import javax.servlet.http.*;
out.println("<html>");
out.println("<body>");
out.println("</form>");
out.println("</body>");
94
out.println("</html>");
}
public void doPost(HttpServletRequest req,HttpServletResponse res)throws
ServletException,IOException
{
res.setContentType("text/html");
PrintWriter out=res.getWriter();
try
{
Class.forName("net.ucanaccess.jdbc.UcanaccessDriver");
con=DriverManager.getConnection("jdbc:ucanaccess://C:/Program
Files/Apache Software Foundation/Tomcat
9.0/webapps/examples/WEB-INF/classes/tydb.accdb");
i=pstmt.executeUpdate();
if(i>0)
{
out.println("Record Deleted.");
}
else
{
out.println("Record Not Deleted.");
}
pstmt=con.prepareStatement("select * from tytable");
rs=pstmt.executeQuery();
if (rs.next())
{
out.println("<h4> ROLLNO   NAME<br></h4>");
do
{
out.println(" "+rs.getInt("rollno")+" 
 "+rs.getString("name"));
95
out.println("<br>");
}while (rs.next());
}
else
{
out.println("\n No data found");
}
}
catch(Exception e)
{
out.println(e);
}
}
}
Question 47:
Write a java networking program to accept the rollno and new name from user on the client
side and on the server side, update the new name according to the rollno given and on the
server side, display the updated record
Question 48:
Write a java networking program to demonstrate the chatting application
Q.1 Explain the concept of thread. In how many ways, thread can be
implemented? Explain wait and notify() with syntax
Q.2 Explain the concept of Connection, statement and result set with suitable
example
96
Q.3 what is Prepared Statement and Callable Statement. Explain with suitable
syntax
Q.5 Explain the method next (), getInt () and getString () from JDBC
Q.6 Explain the life cycle of Servlet. Give any one example of servlet
Q.7 How JDBC can be implemented with Servlet? Discuss all settings and give any
example
Q.9 Explain any four tags available in JSP and also explain any two directives
Q.10 what is Socket and Server Socket? Explain with any one example
97
98