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

  • Home
  • SEARCH
  • 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 6886919
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T05:49:11+00:00 2026-05-27T05:49:11+00:00

I am trying to insert an entry into a database using a form created

  • 0

I am trying to insert an entry into a database using a form created in java. I am able to select from the database without issue, but am having difficulty inserting to it. The issue, I believe, is that I am not converting the integers properly, or perhaps SQL does not take in an int into a Number field. I am not sure. I keep getting a “AWT-EventQueue-0” error, but it is not specifying where.

Here is a snippet of my code for converting my input text:

public void addItem() throws ClassNotFoundException, SQLException{
    Item i1;
    DataAccess DA = new DataAccess();
    this.txtOutput.setText(DA.testResult);
    i1 = new Item();
    i1.setItemId(Integer.parseInt(this.txtItemId.getText()));
    i1.setCategoryId(Integer.parseInt(this.txtCategoryId.getText()));
    i1.setItemName(this.txtItemName.getText());
    i1.setItemDesc(this.txtItemDesc.getText());
    i1.setUnitPrice(Integer.parseInt(this.txtUnitPrice.getText()));
    i1.setUnitStock(Integer.parseInt(this.txtUnitStock.getText()));
    try {
        i1.saveItem();
    } catch (ClassNotFoundException | SQLException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    this.txtItemId.setText("");
    this.txtCategoryId.setText("");
    this.txtItemName.setText("");
    this.txtItemDesc.setText("");
    this.txtUnitPrice.setText("");
    this.txtUnitStock.setText("");
}

Also, here is the code I am using to then insert that data into my database:

public int saveItem() throws ClassNotFoundException, SQLException{
    int rowsAffected=0;
    String strSQL = "INSERT INTO item VALUES (sc_item_item_id_seq.NEXTVAL," + this.getCategoryId() + ",'" + this.getItemName() + "','" + this.getItemDesc() + "'," + this.getUnitPrice() + "," + this.getUnitStock() + ")";
    DataAccess DA = new DataAccess();
    rowsAffected = DA.modifyDatabase(strSQL);
    return rowsAffected;
}

Like I said, I am trying to input integers into fields in my database that are of type Number. Is this doable, or am I mistaken?

Also of note, I have this working without issue on another table, but that table is only taking in strings.

Any help would be appreciated.

Thanks!

Edit:

Here is the error:

Exception in thread "AWT-EventQueue-0" java.lang.NumberFormatException: For input string: ""
at java.lang.NumberFormatException.forInputString(Unknown Source)
at java.lang.Integer.parseInt(Unknown Source)
at java.lang.Integer.parseInt(Unknown Source)
at javagui.views.frmItem.addItem(frmItem.java:243)
at javagui.views.frmItem$1.actionPerformed(frmItem.java:101)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$000(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
  • 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-05-27T05:49:12+00:00Added an answer on May 27, 2026 at 5:49 am

    Yes, you are doing it correctly; inserting the numeric type values without quotes. However, I believe your error is coming from the Integer.parseInt() you are doing in addItem(). Please check that all the strings you are trying to parse to ints are not faulty. You should also put these Integer.parseInt() statements in try/catch(NumberFormatException) block as well to catch these conversion errors.

    Also, since you are doing the try/catch for the exceptions you are looking for, you don’t need to specify what the function throws in the function header. That is to tell the upper level calling functions “Hey, I might throw these exceptions, so you need to catch them.”

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to INSERT INTO a table using the input from another table.
I'm trying to add a new entry into my database, but it's not working.
I am trying to import email communication into a database table using Bulk Insert
I am trying to insert into mysql database dynamically. But I always see only
Trying to insert 315K Gif files into an Oracle 10g database. Everytime I get
I'm trying to insert some import lines into a python source file, but i
I was trying to insert new data into an existing XML file, but it's
I'm trying to insert a column into an existing DataSet using C#. As an
I'm trying to insert objects (NSNumbers) into an NSMutable array, but when I check
i am trying to insert the contents of a CSV file into a database

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.