DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2
  1. #1
    Join Date
    Aug 2005

    Unhappy NumberFormatException

    Hi everyone,
    I need some help.
    I have a program that creates a window with JTexboxes on it and a button. The user is to fill in the textboxes and press the button. When this occurs the program is to retreive the information from the textboxes and then insert it into a database. I used getText() to get the information from the textboxes. That works fine. But when i press the button to send it to the database it gives me an error "NumberFormatException" and then the contents of the textbox in question. Everything seems to be fine. I get the information as a String pass it to the method as a string. Then when i send it to the database I use parseInt() to change it to an Integer because the format of the database column is int(11). I don't know why it is giving me this error. Another funny thing that is happening is that it gives me the error only when i fill in the next following textbox which is also an Integer. Here is the code:

    public void UpdateData(String sex,String account,String id,String fname,
    String lname,String birth,String age,String street,
    String city,String province,String pc,
    String medical,String hphone,String cphone,
    String email,String momfname,String momlname,
    String dadfname,String dadlname,String level,
    String hours,String timefrom,String timeuntil,
    String fee) {

    String s=sex;
    String acc = account;
    String ident = id;
    String first = fname;
    String last = lname;
    String birthday = birth;
    String ageyear = age;
    String streetaddr = street;
    String cityname = city;
    String prov = province;
    String post = pc;
    String med = medical;
    String phone1 = hphone;
    String phone2 = cphone;
    String emailaddr = email;
    String mfirst = momfname;
    String mlast = momlname;
    String dfirst = dadfname;
    String dlast = dadlname;
    String levelname = level;
    String thour = hours;
    String tfrom = timefrom;
    String tuntil = timeuntil;
    String feecost = fee;

    if ((s.equals("m"))||(s.equals("M"))){
    String data = "jdbc:mysql://localhost:3306/athletes";
    try {
    Connection conn = DriverManager.getConnection(
    data, "root", "naofumi");
    Statement st = conn.createStatement();
    st.executeUpdate("INSERT INTO Male" +
    "VALUES ('"+Integer.parseInt((String)acc)+"'"+
    This one triggers it -> ",'"+Integer.parseInt((String)med)+"'"+
    This one gets the error -> ",'"+Integer.parseInt((String)phone1)+"'"+
    } catch (SQLException sq) {
    System.out.println("SQL Error: " + sq.toString() + " "
    + sq.getErrorCode() + " " + sq.getSQLState());
    } catch (Exception e) {
    System.out.println(" Error: " + e.toString()
    + e.getMessage());

    This is the crucial part of the program so if anyone can help please do.

  2. #2
    Join Date
    Oct 2005
    New Jersey
    Are you sure the String passed is parseable to an integer? Anyway, I also noticed that you are unnecessarily casting med again to a String. And try to use PreparedStatements instead of writing a messy code like this. PreparedStatement would be much elegant and save you of several data formatting troubles.
    Happiness is good health and a bad memory.

Similar Threads

  1. Mortgage calculator help
    By vwrado in forum Java
    Replies: 1
    Last Post: 09-26-2005, 05:09 PM
  2. more help!
    By blueandconfused in forum Java
    Replies: 1
    Last Post: 02-22-2005, 05:12 PM
  3. NullPointerException when reading text file
    By Andrew McLellan in forum Java
    Replies: 3
    Last Post: 05-09-2001, 05:34 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
Latest Articles
Questions? Contact us.
Web Development
Latest Tips
Open Source

   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center

We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.