13 Replies Latest reply: Mar 22, 2013 6:42 PM by 979857 RSS

    NumberFormatException: For input string: "1"

    979857
      I'm trying to load data from a file to TimesTen using JDBC but NumberFormatException error occurs.

      This is how my table looks like:

      String tab_wysz = "CREATE TABLE WYSZ(CompanyID TT_INTEGER NOT NULL, ClientID TT_INTEGER NOT NULL, SearchDate DATE NOT NULL, Primary Key(CompanyID, ClientID))";

      How I load data (the same as in the sample TT programs):

      String INPUTFILEWk = "/book/wysz.txt";
      String INSERTWysz = "insert into Wysz values (?,?,?)";

      PreparedStatement pInsOrd = ttcon.prepareStatement(INSERTWysz);

      BufferedReader in = new BufferedReader(new FileReader(plik));
                     String line;
                                                             
                     try {
                          //in = new BufferedReader(new FileReader(INPUTFILEWk));
                          while ((line = in.readLine()) != null) {
                               // Skip comments
                               if (line.charAt(0) == '#') {
                               continue;
                               }
                               outStream.println("Processing data: " +line);
                               String[] fields = line.split(";");

      pInsOrd.setInt(0, Integer.parseInt(fields[0])); // CompanyID
                               pInsOrd.setInt(1, Integer.parseInt(fields[1])); // ClientID
                               pInsOrd.setDate(2, Date.valueOf(fields[2])); // SearchDate

      pInsOrd.executeUpdate();

                               reportSQLWarnings(pInsOrd.getWarnings());
                               // }
                               ttcon.commit();
                          }
                          in.close();
                          pInsOrd.close();
                     } catch (IOException e) {
                               // TODO Auto-generated catch block
                               e.printStackTrace();
                          }
                     catch(SQLException e) {
                          e.printStackTrace();
                     } catch (NumberFormatException e1) {
                               // TODO Auto-generated catch block
                               e1.printStackTrace();
                     }
                               
      }

      File wysz.txt looks like this:

      1;88894;2011-05-17
      28;30799;2011-07-31
      28;48583;2012-02-13
      28;116684;2008-09-23
      28;69301;2009-08-02
      28;64609;2007-09-12
      83;6514;2007-04-29
      83;98420;2008-06-17
      83;40325;2008-09-14

      The file is in UTF-8 encoding, as well as Eclipse which I use to connect database and load data.

      The error looks like this:

      Connected to the database

      Processing data: 1;88894;2011-05-17
      java.lang.NumberFormatException: For input string: "1"
           at java.lang.NumberFormatException.forInputString(Unknown Source)
           at java.lang.Integer.parseInt(Unknown Source)
           at java.lang.Integer.parseInt(Unknown Source)
           at bazy.operacjaInsertILoad(bazy.java:157)
           at bazy_zapytania.testInsertInto(bazy_zapytania.java:114)
           at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
           at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
           at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
           at java.lang.reflect.Method.invoke(Unknown Source)
           at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
           at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
           at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
           at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
           at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
           at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
           at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
           at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
           at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
           at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
           at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
           at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
           at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
           at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
           at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
           at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
           at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
           at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
           at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
           at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
           at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)

      Closing the connection



      Any sugestion what is wrong ?