hi iam final year student in my project i will insert all employee details in search employee page i kept a drop down box for employee Ids i want all employee IDs will display in the drop down box please help me with the code
import java.sql.*; import java.awt.*; import javax.swing.*; import java.awt.event.*; class JComboBoxExample{ public static void main(String[] args) { JFrame f=new JFrame(); f.setLayout(null); JLabel lab=new JLabel("Course Items:"); final JComboBox combo=new JComboBox(); combo.addItem("--Select--"); try{ Class.forName("com.mysql.jdbc.Driver"); Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "root", "root"); Statement st=con.createStatement(); ResultSet rs=st.executeQuery("select * from student"); while(rs.next()){ combo.addItem(rs.getInt("id")); } } catch(Exception e){} JButton b=new JButton("Get"); lab.setBounds(20,20,100,20); combo.setBounds(120,20,150,20); b.setBounds(120,50,80,20); b.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ String value = combo.getSelectedItem().toString(); JOptionPane.showMessageDialog(null,"You have selected '"+value+"' from ComboBox"); } }); f.add(lab); f.add(combo); f.add(b); f.setVisible(true); f.setSize(300,120); } }
actually i want it in jsp page
Ads