在数据库中插入XLSX数据

我已经创build了一个小应用程序,将用于读取excel .xlsx文件的条形码扫描器(或手写在jtextfield中的数字),并将相关值写入sqlite文件。

数据是“固定的”(它始终是前7列,格式为Excel中的文本),但行号不是。

我有程序工作,但本周突然停止工作(我已经尝试恢复到早期的提交,也没有运气),我正在努力了解我在做什么错了。

class ImportWorker extends SwingWorker<Integer , Integer>{ JProgressBar jpb; int max; Sheet sheet; File file; //Passo i valori di questa classe come riferimenti di oggetti presenti nell'EDB, cosi' posso aggiornare i valori li' public ImportWorker(JProgressBar jpb, int max, Sheet sheet, File file){ this.jpb = jpb; this.max = max; this.sheet = sheet; this.file = file; } @Override protected Integer doInBackground() throws Exception { //Svolgo il mio Import dentro un Thread separato dall'EDB cosi' il programma non si blocca Row row; String sql = "jdbc:sqlite:"+dbPath; try{ conn = DriverManager.getConnection(sql); String sql2 = "DELETE FROM libri"; Statement = conn.prepareStatement(sql2); Statement.execute(); Statement.close(); for (int i = 0; i <= sheet.getLastRowNum(); i++) { //attivo progress bar con il ciclo per visualizzare lo stato di caricamento del file int pbpercentage = (100 * i)/(max); //conversione dei valore ed inserimento dentro il database row = sheet.getRow(i); row.getCell(0).setCellType(Cell.CELL_TYPE_STRING); String Nome = row.getCell(0).getStringCellValue(); row.getCell(1).setCellType(Cell.CELL_TYPE_STRING); String Autore = row.getCell(1).getStringCellValue(); row.getCell(2).setCellType(Cell.CELL_TYPE_STRING); String Casa = row.getCell(2).getStringCellValue(); row.getCell(3).setCellType(Cell.CELL_TYPE_STRING); String Codice = row.getCell(3).getStringCellValue(); row.getCell(4).setCellType(Cell.CELL_TYPE_STRING); String Prezzo = row.getCell(4).getStringCellValue(); row.getCell(5).setCellType(Cell.CELL_TYPE_STRING); String Anno = row.getCell(5).getStringCellValue(); row.getCell(6).setCellType(Cell.CELL_TYPE_STRING); String Indice = row.getCell(6).getStringCellValue(); String sql1 = "INSERT INTO libri (Nome, Autore, Casa, Codice, Prezzo, Anno, Indice) VALUES (?, ?, ?, ?, ?, ?, ?)"; Statement = conn.prepareStatement(sql1); Statement.setString(1, Nome); Statement.setString(2, Autore); Statement.setString(3, Casa); Statement.setString(4, Codice); Statement.setString(5, Prezzo); Statement.setString(6, Anno); Statement.setString(7, Indice); Statement.execute(); Statement.close(); publish(pbpercentage); } conn.close(); }catch(SQLException e){ JOptionPane.showMessageDialog(null, "leggi() SwingWorker", "Errore", JOptionPane.ERROR_MESSAGE); e.printStackTrace(); } return null; } @Override protected void process(List<Integer> chunks) { //Aggiornamento della percentuale della progress bar int i = chunks.get(chunks.size()-1); jpb.setValue(i); } @Override protected void done() { //Imposto il messaggio dei due Jlabel DateFormat dateFormat = new SimpleDateFormat("HH:mm:ss"); Calendar cal = Calendar.getInstance(); eventi.setText(dateFormat.format(cal.getTime())); eventi2.setText("FILE "+ file.getName() +" IMPORTATO"); //Nascondo la barra jpb.setVisible(false); setCursor(null); } } 

这是我使用的代码的相关部分,它使用了一个swingworker,以便我可以更新进度条,并检查操作的状态,问题是,在我select文件的程序中,for循环开始和结束几秒钟后立即打印出标签“File”FILE_NAME“importato”(应该在整张纸上完成)。

我已经尝试添加System.out.println进程的各个阶段,似乎它正确地进入for循环,但只是退出,甚至没有达到第一个循环的结束。

请原谅其他语言的意见,我很高兴翻译任何你不明白!

PS的数据库表被称为“libri”,它有8列(第一个是名为Id的PK)

谁能帮我吗?