嘿,为什么在尝试将数据输入表时出现此错误。
org.springframework.dao.DataIntegrityViolationException
PreparedStatementCallback; SQL [INSERT INTO INS_RAZNO.ZAPOSLENICI_TEST VALUES(?,?,?,?,?,?)] ORA-01722:号码无效
嵌套的异常是java.sql.SQLException:ORA-01722:无效的数字
似乎整数和字符串有问题,但是我对包含整数和字符串的类似方法也没问题,但是效果很好。有什么想法可以解决这个问题吗?
-d
表的架构为:
@Override
public void getExcell2() {
final String PATH = "C:\\Workspace\\zaposlenici.xlsx"; //putanja do excel file-a
try {
Workbook workbook = WorkbookFactory.create(new File(PATH)); //High level representation of a Excel workbook.
Sheet sh = workbook.getSheetAt(0); //High level representation of a Excel worksheet.
DataFormatter dataFormatter = new DataFormatter(); //DataFormatter contains methods for formatting the value stored in an Cell.
List<String> lista = new ArrayList<String>(); //Lista sa vrijednostima svih ćelija
sh.forEach(row -> { //sheet.forEach row
row.forEach(cell -> { //row.forEach cell
String cellvalue = dataFormatter.formatCellValue(cell); //formatira ćelije u string tip
lista.add(cellvalue);
});
});
workbook.close();
ArrayList<String> lista1 = new ArrayList<String>();
ArrayList<String> lista2 = new ArrayList<String>();
ArrayList<String> lista3 = new ArrayList<String>();
ArrayList<String> lista4 = new ArrayList<String>();
ArrayList<String> lista5 = new ArrayList<String>();
ArrayList<String> lista6 = new ArrayList<String>();
@SuppressWarnings("unchecked")
ArrayList<String>[] liste = new ArrayList[]{lista1, lista2, lista3, lista4, lista5, lista6};
for (int i=0 ; i< lista.size(); i ++ ){
if(lista.get(i) == null) {
liste[i % 6].add("NULL");
}
else if (lista.get(i) == "") {
liste[i % 6].add("NULL");
}
else {
liste[i % 6].add(lista.get(i));
}}
jdbcTemplate.batchUpdate("INSERT INTO INS_RAZNO.ZAPOSLENICI_TEST VALUES (?, ?, ?, ?, ?, ?)", new BatchPreparedStatementSetter() {
@Override //"INSERT INTO INS_RAZNO.BULK_TEST VALUES (?, ?, ?)"
public void setValues(PreparedStatement ps, int i) throws SQLException {
ps.setString(1, lista1.get(i));
ps.setString(2, lista2.get(i));
ps.setString(3, lista3.get(i));
ps.setString(4, lista4.get(i));
ps.setString(5, lista5.get(i));
ps.setString(6, lista6.get(i));
}
@Override
public int getBatchSize() {
return lista2.size();
}
});
} catch (EncryptedDocumentException | InvalidFormatException | IOException e) {
e.printStackTrace();
}
}
答案 0 :(得分:3)
尝试将字符串转换为数字并且无法将字符串转换为数字时,会发生ORA-01722错误
答案 1 :(得分:2)
我解决了这个问题,它是由第一行具有所有用于列名称的字符串组成的。 只是不估算第一行。