how to retrieve data into combo from database in java applet?

how to retrieve data into combo from database in java applet?

hi,. i have written applet codes for linking two frames and database connectivity but the problem is, the database is not retrieving data into the combo..please somebody help me for the right set of codes.i have attached the codes.

//First page
import java.awt.*;
import java.sql.SQLException;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
class gwf extends Frame implements ActionListener
{   public Label l1,l2,l3;
    public TextField tf1,tf2,tf3;
    public JComboBox c1,c2;
    public Button b1,b2;
    public Panel p1,p2;
    String s1;
    gwf(){
        setLayout(new GridLayout(5,1));
        setTitle("FIRST PAGE");
        l1 = new Label("Choose Department");
        c1 = new JComboBox();
        c1.addItem("--select--");
        c1.addItem("Science");
        c1.addItem("Fashion");
        c1.addItem("IT Corporate");
        c1.addItem("Finance");
        c1.addItem("Sociology");
        p1 = new Panel();
        p2 = new Panel();
        b1 = new Button("SUBMIT");
        p1.add(l1);
        p1.add(c1);
        p2.add(b1);
        add(p1, "Center");
        add(p2, "South");
        b1.addActionListener(this);
        setSize(500, 500);
        setVisible(true);}
     public void actionPerformed(ActionEvent e) {
    gwf1 g = new gwf1(s1);
    dispose();}
public static void main(String[] args) throws SQLException {
    gwf g = new gwf();
    }}

//Second page import javax.swing.*; import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.Statement; class gwf1 extends Frame implements ActionListener { private static final String String =null; Label l1; TextField t1; JComboBox c1,c2; Panel p1,p2; Button b1; String s1, s2; Statement st; ResultSet rs=null; Connection con;

public void init() { try{ Class.forName("org.postgresql.Driver"); con = DriverManager.getConnection("jdbc:postgresql://localhost:5432/departments","postgres", "postgres"); Statement st= con.createStatement(); ResultSet rs=st.executeQuery("SELECT rolename from role WHERE deptid=1234"); while(rs.next()){ c1.addItem(rs.getInt("role_name")); }} catch(Exception e) { e.printStackTrace(); } } public gwf1(String s1) { this.s1 = s1; setLayout(new GridLayout(5, 1)); setTitle("Second Page"); l1 = new Label("Enter Role"); c1 = new JComboBox(); c1.addItem("--select--"); b1 = new Button("SUBMIT"); p1 = new Panel(); p2 = new Panel(); p1.add(l1); p1.add(c1); p2.add(b1); add(p1, "Center"); add(p2, "South"); b1.addActionListener(this); setSize(400, 500); setVisible(true); } public void actionPerformed(ActionEvent e1) { JOptionPane.showMessageDialog(this, "The generated Id is:"); dispose(); }}

View Answers

March 10, 2011 at 11:18 AM

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);
    }
}









Related Tutorials/Questions & Answers:
how to retrieve data into combo from database in java applet?
how to retrieve data from database ?????/
Advertisements
how to retrieve data from database ?????/
how to retrieve data from database ?????/
how to retrieve data from database ?????/
retrieve the data to text fields from database on clicking the value of combo box
how to retrieve data from database
how to use bean to retrieve data from database
How to retrieve data from database by using combo box value in jsp? - JSP-Servlet
How to Retrieve Data from the database and write into excel file using Java
How to retrieve and display image from database in Java?
retrieve data from database with hyperlink
Retrieving Data from Database to fill Combo Box
retrieve data from mysql database
How to retrieve data by using combo box value in jsp? - JSP-Servlet
Data retrieve from mysql database
Retrieve multiple data from database into Table.....
How to retrieve image from database
retrieve data from database using jsf
retrieve data from mysql database and store it in a variable ?
how to retrieve data from database using combobox value without using request.getParameter in jsp - JSP-Servlet
Populate a combo box using data from a database
How to retrieve data by using combo box value in jsp? - JSP-Servlet
How to retrieve image from mysql database in JSP?
Retrieve Data from the database and write into excel file
Retrieve data from database in swing application
How to retrieve image from database in Servlet?
Retrieve data from the database and write into ppt file
how i conditional access the data from database using combo box. - JSP-Servlet
How to retrieve blob image from database in JSP?
How to store and retrieve image from database in JSP?
How to retrieve data using combo box value in jsp? - JSP-Servlet
How to Retrieve data from database in jsp
Acees data from database using combo box - JSP-Servlet
How to retrieve data by using combo box value in jsp? - JSP-Servlet
How to Retrieve Data from Facebook Using PHP
How to Retrieve Data from Facebook Using PHP
how to retrieve images from database to jsp?
how to store and retrieve image from database
retrieve data from database in java swing form using prev n next buttons
retrieve data from database in java swing form using prev n next buttons
retrieve related data from database using jsp and mysql
how to retrieve image from mysql database using java and show it in HTML img tag ?
Retrieve data from database by using sql tag of JSTL SQL library
how we retrieve image from database
how to insert, retrieve data from,to db(code)....
Retrieve The Data From MySql Datbase
how to insert, retrieve data from,to db(code)....
how to store and retrieve images int and from the database using php
How to retrieve image from database using jsp and servlet?

Ads