Jackcess Numberformatexception

蓝咒 提交于 2019-12-20 05:53:18

问题


I'm trying to create a program which takes input from a CSV-file and writes it to a Java-created Access database and table. The program uses a while-loop to go through the CSV-file. The first line of the file is written perfectly to the database, but it crashes at the second line, while trying to write the same kind of input to the table. How can I solve this? Here's my code so far:

public void GPXtoAccess() {
    try {
        Access = new Scanner(DummyCSV);
        Scanner = new Scanner(DummyCSV);

        while (Access.hasNextLine()) {
            Scanner.useDelimiter(";");
            GPXlat = Scanner.next();
            GPXlon = Scanner.next();
            GPXtime = Scanner.next();
            GPXname = Scanner.next();
            GPXdesc = Scanner.next();

            try {
                GPXTable.addRow(Column.AUTO_NUMBER, GPXlat, GPXlon, GPXtime, GPXname, GPXdesc);
            } catch (IOException T) {
                System.out.println("Error: " + T);
                System.out.println("Error is thrown while writing data to table");
            }
        }
    } catch (FileNotFoundException M) {
        System.out.println("Error: " + M);
    }
}

回答1:


In your code you have use Scanner.next() which returns String value. Most of the time your table column values not match with String that is why you getting Numberformatexception




回答2:


Most probably you may try to convert a String type one to a numeric type. Please check data types of your data that you are trying to use.



来源:https://stackoverflow.com/questions/47859910/jackcess-numberformatexception

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!