import java.io.*;
import java.sql.*;
import javax.sql.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
public class Slip10 extends Frame implements
ItemListener
{
Connection con;
ResultSet rs;
Statement state;
Choice choice1;
TextField t1,t2,t3;
Label l1,l2,l3;
public Slip10()
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con=DriverManager.getConnection("jdbc:odbc:myd
sn");
state=con.createStatement();
String sql="select *
from student";
rs=state.executeQuery(sql);
setLayout(new
FlowLayout());
setSize(300,300);
t1=new
TextField(10);
t2=new
TextField(10);
t3=new
TextField(10);
l1=new Label("Roll
No: ");
l2=new
Label("Name:");
l3=new
Label("Percentage:");
choice1=new
Choice();
while(rs.next())
{
choice1.add(rs.getString(1));
}
}catch(Exception e)
{
System.out.println(e);
}
add(choice1);
add(l1);
add(t1);
add(l2);
add(t2);
add(l3);
add(t3);
choice1.addItemListener(this);
addWindowListener(new
WindowAdapter()
{
public void
windowClosing(WindowEvent we)
{
setVisible(false);
System.exit(0);
dispose();
}
});
}
public void itemStateChanged(ItemEvent
ie)
{
try
{
state=con.createStatement();
int
no=Integer.parseInt(choice1.getSelectedItem());
rs=state.executeQuery("select * from student
where Code=" +no);
while(rs.next())
{
t1.setText(rs.getString(1));
t2.setText(rs.getString(2));
t3.setText(rs.getString(3));
}
}catch(Exception e)
{
System.out.println(e);
}
}
public static void main(String args[])
{
Slip10 obj=new Slip10();
obj.setVisible(true);
}
}
No comments:
Post a Comment