Slip9
Q1. Write a JDBC program to delete the records of
employees whose names are starting with ‘A’ character.
import
java.sql.*;
import
java.io.*;
import
javax.sql.*;
class
slip9
{
public static void main(String
args[])
{
Connection con;
Statement stmt;
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con=DriverManager.getConnection("jdbc:odbc:lab.dsn");
if(con==null)
{
System.out.println("Connection Failed....");
System.exit(1);
}
System.out.println("Connection Established...");
stmt=con.createStatement();
int no =
stmt.executeUpdate("Delete from employee where name like 'A%'");
if(no!=0)
System.out.println("Delete
Data sucessfully.....");
else
System.out.println("Data NOT Deleted");
con.close();
}
catch(Exception e)
{
System.out.println(e);
}
}
}
Q2. Write a Multithreading program in java using
Runnable interface to move text on the frame as follow:
Starting Position of Text
import
java.applet.Applet;
import
java.awt.*;
public
class slip9b extends Applet implements Runnable
{
Thread
t;
int
x,y,k;
int
counter=0;
public
void init()
{
x=10;
k=0;
y=200;
t=new
Thread(this);
t.start();
}
public
void run()
{
try
{
while(true)
{
repaint();
Thread.sleep(1000);
++counter;
}
}
catch(Exception
e)
{ }
}
public
void paint(Graphics g)
{
g.setFont(new
Font("ariel",Font.BOLD,30));
FontMetrics
fm=g.getFontMetrics();
String
s="Vinita";
Dimension
d=getSize();
g.drawString(s,x,y);
if(k==0)
{
x=360;
y=25;
k=1;
}
else
if(k==1)
{
x=700;
y=200;
k=2;
}
else
if(k==2)
{
x=360;
y=400;
k=3;
}
else
if(k==3)
{
x=10;
y=200;
k=0;
}
}
}
<html>
<body>
<Applet
code=slip9b.class height=600 width=800>
</Applet>
</body>
</html>