Slip3
Q1. Write a JDBC
program to displays the details of employees (eno, ename, department, sal)
whose department is “Computer Science”.
import
java.sql.*;
import
java.io.*;
import
javax.sql.*;
class
slip2
{
public
static void main(String args[])
{
Connection
con;
Statement
state;
ResultSet
rs;
int
ch;
boolean
flag=true;
String
decision;
int
no;
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con
= DriverManager.getConnection("jdbc:odbc:lab.dsn");
//System.out.println("Statement
object created");
BufferedReader
br=new BufferedReader(new InputStreamReader(System.in));
ch=Integer.parseInt(br.readLine());
state=con.createStatement();
String
sql="select * from employees where department='Computer Science'";
rs=state.executeQuery(sql);
while(rs.next())
{
System.out.println("\n");
System.out.print("\t"
+rs.getInt(1));
System.out.print("\t"
+rs.getString(2));
System.out.print("\t"
+rs.getString(3));
System.out.print("\t"
+rs.getInt(4));
}
}
catch(Exception
e)
{
System.out.println(e);
}
}
}
Q2. Write a java
program to simulate traffic signal using multithreading.
Tsgnl.java
import
java.io.*;
import
java.util.*;
import
java.applet.Applet;
import
java.awt.*;
public
class Tsgnl extends Applet implements Runnable
{
Thread
t;
int
x=0;
public
void run()
{
repaint();
}
public
void init()
{
Tsgnl
ts=new Tsgnl();
t=new
Thread(ts);
t.start();
setSize(500,500);
setBackground(Color.pink);
}
public
void paint(Graphics g)
{
g.setColor(Color.blue);
g.fillRect(200,100,100,270);
g.setColor(Color.white);
g.drawOval(220,120,70,70);
g.drawOval(220,200,70,70);
g.drawOval(220,280,70,70);
if(x==0)
{
g.setColor(Color.red);
g.fillOval(220,120,70,70);
x=1;
}
else
if(x==1)
{
g.setColor(Color.yellow);
g.fillOval(220,200,70,70);
x=2;
}
else
{
g.setColor(Color.green);
g.fillOval(220,280,70,70);
x=0;
}
try
{
Thread.sleep(3000);
}
catch(Exception
e)
{
e.printStackTrace();
}
repaint();
}
}
Tsgnl.html
<html>
<body>
<applet
code="Tsgnl.class" height=300 width=300>
</applet>
</body>
</html>
Javac
Tsgnl.java
Appletviewer Tsgnl.html