Write a java program to display the records of the student (rno,sname,per) on the screen by selecting rno from the Choice component.
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:my1dsn.dsn"); 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 rno=Integer.parseInt(choice1.getSelectedItem()); rs=state.executeQuery("Select * from student where rno="+rno); 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); }}
Write a java program to display the records of the student (rno,sname,per) on the screen by selecting rno from the Choice component.
Reviewed by
on
April 27, 2015
Rating: