Results 1 to 3 of 3
  1. #1
    aleksandar is offline Member
    Join Date
    Feb 2011
    Posts
    2
    Rep Power
    0

    Default Problem when inserting in java

    Hello
    I'm new in Java and i'm updating some code that i inherited.In that code all fields need to be filled. When i insert new field that may be blank i cant write in data base and i get the next error :java.lang.NumberFormatException: For input string: ""
    at java.lang.NumberFormatException.forInputString(Num berFormatException.java:48)
    on that field i have this code on insert
    prstINSERT_GLAVA.setString(colonaGlavaZABELESKA_G, controlZABELESKA_G.getText());
    Please help
    Thank You

  2. #2
    doWhile is offline Moderator
    Join Date
    Jul 2010
    Location
    California
    Posts
    1,642
    Rep Power
    6

    Default

    Read the API for the classes/methods you are using. Without code or any more information its a guess, but NumberFormatException's are typically thrown when trying to parse a string into a primitive number value..and will be thrown for an empty string.

  3. #3
    aleksandar is offline Member
    Join Date
    Feb 2011
    Posts
    2
    Rep Power
    0

    Default

    The thing is that i enter data for some fields and i skip one and when a try to submit i get that error here is the part of the code when i try to insert

    public boolean insertPomagalaGlava()
    {
    boolean b = false;
    try
    {
    long l = System.currentTimeMillis();

    //////////////////// 1 - 5 ///////////////////////////////////////////////////////////////////
    // NUMBER(4)
    prstINSERT_GLAVA.setInt(colonaGlavaGODINA, Integer.parseInt(controlGODINA.getText()));
    // NUMBER(8)
    prstINSERT_GLAVA.setLong(colonaGlavaBROJ, Long.parseLong(controlBROJ.getText()));
    // NUMBER(3)
    prstINSERT_GLAVA.setInt(colonaGlavaOPSTINAID, Integer.parseInt(controlOPSTINAID.getText()));
    // NUMBER(13)
    prstINSERT_GLAVA.setLong(colonaGlavaEMBG, Long.parseLong(controlEMBG.getText()));
    // VARCHAR2(10)
    prstINSERT_GLAVA.setString(colonaGlavaPOTVRDA, controlPOTVRDA.getText());

    //////////////////// 6 - 10 ///////////////////////////////////////////////////////////////////
    // DATE
    prstINSERT_GLAVA.setDate(colonaGlavaDATUM_POTVRDA, pckDel.Reku.strToSqlDate(controlDATUM_POTVRDA.getT ext()));
    // DATE
    prstINSERT_GLAVA.setDate(colonaGlavaDATUM_ZAVERKA, pckDel.Reku.strToSqlDate(controlDATUM_ZAVERKA.getT ext()));
    // VARCHAR2(5)
    prstINSERT_GLAVA.setString(colonaGlavaDIJAID1, controlDIJAID1.getText());
    // VARCHAR2(2)
    prstINSERT_GLAVA.setString(colonaGlavaDIJAID2, controlDIJAID2.getText());
    // NUMBER(8)
    prstINSERT_GLAVA.setLong(colonaGlavaFAKSIMIL, Long.parseLong(controlFAKSIMIL.getText()));

    //////////////////// 11 - 12 ///////////////////////////////////////////////////////////////////
    // NUMBER(3)
    prstINSERT_GLAVA.setInt(colonaGlavaORTOP_VID, Integer.parseInt(controlORTOP_VID.getText()));
    System.out.println("DO TUKA");
    prstINSERT_GLAVA.setLong(colonaGlavaEMBG_PODNOSITE L, Long.parseLong(controlEMBG_PODNOSITEL.getText()));

    System.out.println("Kaj Podosnitel");
    prstINSERT_GLAVA.setString(colonaGlavaZABELESKA_G, controlZABELESKA_G.getText());
    // VARCHAR(20)
    prstINSERT_GLAVA.setString(colonaGlavaVRABOTEN, controlVRABOTEN.getText());

    prstINSERT_GLAVA.execute();

    db.conn.commit();
    long n = System.currentTimeMillis();
    System.out.println("Insert PomagalaGlava : "+(n-l)+" msec");
    return true;
    }
    catch(Exception exc)
    {
    exc.printStackTrace();
    try
    {
    db.conn.rollback();
    }
    catch(Exception e)
    {
    e.printStackTrace();
    }
    return false;
    }
    }//insertPomagalaGlava
    The field that can be blank in same cases is controlZABELESKA.Thank You

Similar Threads

  1. Problem inserting into database
    By Unnel in forum JDBC
    Replies: 13
    Last Post: 01-23-2011, 09:23 PM
  2. problem with inserting new record
    By gerard kowara in forum JDBC
    Replies: 1
    Last Post: 10-26-2010, 11:33 AM
  3. Replies: 5
    Last Post: 04-05-2010, 01:24 PM
  4. Replies: 1
    Last Post: 12-30-2008, 04:39 PM
  5. Replies: 0
    Last Post: 12-24-2007, 09:47 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •