Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8428323
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T05:01:17+00:00 2026-06-10T05:01:17+00:00

I am building a stand alone application using java swing and I am using

  • 0

I am building a stand alone application using java swing and I am using an excel 2007 sheet as the back end for storing the data. I have successfully inserted text values and integer values from the GUI to the excel sheet. Now I am having trouble with inserting the selected values into the JCombobox on the excel sheet. Can anyone tell me how to do it?

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.sql.*;
import java.io.*;

public class ExcelTest extends Frame implements ActionListener

{
 Label l1;
 TextField textID, textFirstName, textLastName, textJobTitle;
 Button First, Next, Previous, Last;
 JComboBox comboGrade;


 public ExcelTest(String s) {

  setTitle("Testing connection");
  setLayout(null);
  l1 = new Label("Job Title");
  textJobTitle = new TextField(20);
  l1.setBounds(50, 100, 200, 50);
  textJobTitle.setBounds(300, 110, 135, 30);

  textID = new TextField(10);
  textID.setBounds(300, 160, 135, 30);

  textFirstName = new TextField(20);
  textFirstName.setBounds(300, 210, 135, 30);

  textLastName = new TextField(20);
  textLastName.setBounds(300, 260, 135, 30);


  final String[] grade = {
   "X",
   "Y",
   "Z"
  };
  comboGrade = new JComboBox(grade);
  comboGrade.setEditable(true);
  comboGrade.addActionListener(new ActionListener() {

   public void actionPerformed(ActionEvent e) {
    if (e.getActionCommand().equals("comboBoxEdited")) {
     System.out.println("Adding new player!");
     comboGrade.insertItemAt(comboGrade.getSelectedItem(), 0);
    }
   }
  });


  comboGrade.setBounds(300, 300, 135, 30);


  First = new Button("First");
  First.setBounds(200, 600, 80, 40);

  Previous = new Button("PREVIOUS");
  Previous.setBounds(400, 600, 80, 40);

  Next = new Button("NEXT");
  Next.setBounds(600, 600, 80, 40);

  Last = new Button("LAST");
  Last.setBounds(800, 600, 80, 40);

  add(l1);
  add(textJobTitle);

  add(textFirstName);
  add(textLastName);
  add(textID);
  add(comboGrade);

  add(First);
  First.addActionListener(this);
  add(Next);
  Next.addActionListener(this);
  add(Previous);
  Previous.addActionListener(this);
  add(Last);
  Last.addActionListener(this);

  setSize(1000, 1000);
  setVisible(true);
  setResizable(false);

 }

 public void actionPerformed(ActionEvent ae) {


  try {
   //String id="";
   //String first_name="";
   //String last_name="";
   //String job="";


   String value1 = textID.getText();

   String value2 = textFirstName.getText();

   String value3 = textLastName.getText();

   String value4 = textJobTitle.getText();

   String value5 = comboGrade.getText();




   //connect to the database  
   Class.forName("sun.jdbc.odbc.JdbcOdbcDriver").newInstance();
   Connection con = DriverManager.getConnection("jdbc:odbc:Testing");

   //Execute some sql and load the records into the resultset

   Statement stmt = con.createStatement();
   String q = "insert into [sheet1$](id,first_name,last_name,job_Title,grade) values     ('" + value1 + "','" + value2 + "','" + value3 + "','" + value4 + "','" + value5 + "')";
   int ds = stmt.executeUpdate(q);
   System.out.println("Data is inserted");

   //move the cursor to the first record and get the data




   stmt.close();
   con.close();

  } catch (java.lang.ClassNotFoundException e) {
   System.err.print("ClassNotFoundException: ");
   System.err.println(e.getMessage());
  } catch (SQLException err) {
   JOptionPane.showMessageDialog(ExcelTest.this, err.getMessage());
  }

  //catch(java.lang.InstantiationException i){}
  catch (Exception e) {}
 }


 public static void main(String s[]) throws NullPointerException {

  ExcelTest myFrame = new ExcelTest("MANAGEMENT OF STATEMENT OF WORKS");

  myFrame.addWindowListener(new WindowAdapter() {
   public void windowClosing(WindowEvent we) {
    System.exit(0);
   }
  });
 }

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T05:01:19+00:00Added an answer on June 10, 2026 at 5:01 am

    This line:

    String value5=comboGrade.getText();
    

    should be something like:

    String value5 = (String) comboGrade.getSelectedItem();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am buliding a stand alone application using java swing. and excel 2007 sheet
Building a stand alone WPF application that uses a MSSQL backend. I would like
I am currently building an application using ASP.NET MVC. The data entry pages are
Building my first SL MVVM application (Silverlight4 RC) and have some issues i don't
We have jboss logging enabled in our application. Currently we are using the 'Rotating-file-handler'
I'm building a multi-threaded client side javascript application, and I would like to have
I'm building an application that serves up data to a standalone Google Earth client.
For illustration purposes let us say I'm building a simple blog application and have
I am building application which needs to have OOP style MySQL query builder. I
Building an inventory system. I have lots of products and each product has three

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.