import java.awt.*;
import java.awt.event.*;
import java.sql.*;
class studf extends Frame implements ItemListener
{
Choice
c1 = new Choice();
Label
l1 =new Label("Rollno:");
Label
l2 =new Label("SName:");
Label
l3 =new Label("Percentage:");
Label
l4 =new Label();
Label
l5 =new Label();
Label
l6 =new Label();
Label
l7=new Label("Select Rno:");
Connection
con;
Statement
stmt;
ResultSet
rs;
studf()throws
Exception
{
setSize(300,300);
setLayout(null);
setVisible(true);
l7.setBounds(50,50,70,30);
l7.setVisible(true);
add(l7);
c1.setBounds(130,50,100,20);
c1.setVisible(true);
add(c1);
c1.addItemListener(this);
l1.setBounds(50,90,70,30);
l1.setVisible(true);
add(l1);
l2.setBounds(50,130,70,30);
l2.setVisible(true);
add(l2);
l3.setBounds(50,170,70,30);
l3.setVisible(true);
add(l3);
l4.setBounds(130,90,70,30);
l4.setVisible(true);
add(l4);
l5.setBounds(130,130,70,30);
l5.setVisible(true);
add(l5);
l6.setBounds(130,170,70,30);
l6.setVisible(true);
add(l6);
this.addWindowListener(new
WindowAdapter(){
public void windowClosing(WindowEvent
we)
{
dispose();
}
});
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con=DriverManager.getConnection("jdbc:odbc:dbAccess","my","asa");
stmt
=con.createStatement();
rs=stmt.executeQuery("select
* from student");
while(rs.next())
{
c1.addItem(rs.getString(1));
}
rs.close();
}
public
void itemStateChanged(ItemEvent ie)
{
try
{
int
rlno;
rlno=Integer.parseInt(c1.getSelectedItem());
rs=stmt.executeQuery("select
* from student where rno="+rlno);
rs.next();
l4.setText(""+rs.getInt(1));
l5.setText(rs.getString(2));
l6.setText(""+rs.getInt(3));
rs.close();
}catch(Exception e)
{
}
}
public
static void main(String args[])throws Exception
{
studf
s = new studf();
}
}
Post a Comment