English 中文(简体)
斯堪的纳 throw夫。 在处理大型CSV档案时没有发现的线(750000条线)
原标题:Scanner throwing java.util.NoSuchElementException: No line found when processing large CSV file (750000 lines)

Hello I am currently processing a large Excel document containing the yearly temperatures of each of the world s cities over around 270 years and am receiving an error java.util.NoSuchElementException: No line found after around 75000 lines. Each line has 8 elements in them which get stored in an arraylist of type city which has variables: CountryName, CityName, AvgTemp, MinTemp, MaxTemp, Longitude, Latitude and Year. The method I am using to debug this is as follows:

 private static void FillPopulation(){
        Connection con = null;

        try{
            con = DriverManager.getConnection(DATA_BASE);
            Scanner lineScanner = new Scanner(new File(EXCEL_TO_PROCESS));
            
            lineScanner.nextLine();
            
            while (lineScanner.hasNext()) {
                String line = lineScanner.nextLine();
                Scanner rowScanner = new Scanner(line);
                rowScanner.useDelimiter(",");
                String year = rowScanner.next();
                String avgTemp = rowScanner.next();
                String minTemp = rowScanner.next();
                String maxTemp = rowScanner.next();
                String cityName = rowScanner.next();
                String countryName = rowScanner.next();
                String latitude = rowScanner.next();
                String longitude = rowScanner.next();
                if (avgTemp.equals("")) {
                    avgTemp = "0";
                 }
                 if (minTemp.equals("")) {
                    minTemp = "0";
                 }
                 if (maxTemp.equals("")) {
                    maxTemp = "0";
                 }
                String query = "INSERT INTO CityTemps VALUES( " + countryName + " ,  " + cityName + " , " + year +", "+avgTemp+", "+maxTemp+", "+minTemp+",  "+latitude+" ,  "+longitude+" )" ;
                System.out.println(query);
                Statement stmt = con.createStatement();
                stmt.execute(query);

            }
        }catch(Exception e){
            e.printStackTrace();
        }
    }

不能确定造成这种情况的原因,我们非常赞赏任何解释。

问题回答

暂无回答




相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签