请参阅以下代码。
private void printToConsole(List cellDataList) {
for (int i = 1; i < cellDataList.size(); i++) {
List cellTempList = (List) cellDataList.get(i);
System.out.println(cellTempList);
}
}
如何从上面的代码中获取要插入数据库的数据。
String sql2 = "INSERT INTO Daily_Report (field1,field2,field3,field4,field5,field6,field7,field8,field9,field10,field11,field12,field13,field14) values(?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
preparedstatement = con3.prepareStatement(sql2);
//Statement stmt = con3.createStatement();
System.out.println("1");
preparedstatement.setString(1, field1);
preparedstatement.setString(2, field2);
preparedstatement.setString(3, field3);
preparedstatement.setString(4, field4);
preparedstatement.setString(5, field5);
preparedstatement.setString(6, field6);
preparedstatement.setString(7, field7);
preparedstatement.setString(8, field8);
preparedstatement.setString(9, field9);
preparedstatement.setString(10, field10);
preparedstatement.setString(11, field11);
preparedstatement.setString(12, field12);
preparedstatement.setString(13, field13);
preparedstatement.setString(14, field14);
preparedstatement.executeUpdate();
你能告诉我......
答案 0 :(得分:0)
之类的东西?
for (int i = 0; i < rowDataList.size() && i <14; i++) {
preparedstatement.setString(i+1, rowDataList.get(i));
}
for (int i = rowDataList.size()+1; i <=14; i++) {
preparedstatement.setString(i+1, "");
}
preparedstatement.executeUpdate();
答案 1 :(得分:0)
写这个;
for (int i = 0; i < cellDataList.size(); i++){
stmt.executeUpdate ((String) cellDataList.get (i));
}
答案 2 :(得分:0)
String sql2 = "INSERT INTO Daily_Report (field1,field2,field3,field4,field5,field6,field7,field8,field9,field10,field11,field12,field13,field14) values(?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
preparedstatement = con3.prepareStatement(sql2);
for (int i = 1; i < cellDataList.size(); i++) {
List cellTempList = (List) cellDataList.get(i);
for (int i = 0; i <14; i++) {
preparedstatement.setString(i+1, cellTempList.size() > i ? cellTempList.get(i) : "");
}
}
假设:
cellDataList
是您正在阅读的Excel中所有行的列表。 cellTempList
是表示行内容的列表