在下面的代码中,我解析了所有文件名,然后我试图检查数据库以查看它是否存在于其中。我在下面做错了什么?如果是这样,你能告诉我吗?
同样在执行命令中,我收到一条错误消息,提示无法将 listofFiles 解析为变量。
public class FileGetName {
public String fileName;
public static void main(String[] args) {
File folder = new File("C");
File[] listOfFiles = folder.listFiles();
for (int i = 0; i < listOfFiles.length; i++) {
if (listOfFiles[i].isFile()) {
System.out.println(listOfFiles[i].getName());
} else if (listOfFiles[i].isDirectory()) {
System.out.println("Directory " + listOfFiles[i].getName());
}
}
}
public void doesFileExistinDB(String fileName) {
PreparedStatement pst = null;
Connection conn = null;
ResultSet rs= null;
try {
conn = DBConnect.getInstance().dbOracleConnect();
String sql= "select * from PO_Parent_List where" +
" po_number in (fileName)";
pst = conn.prepareStatement(sql);
rs = pst.executeQuery();
}
catch (Exception e) {
System.out.println(e);
}
}
public void execute() {
if (listOfFiles[i].isFile())
{
String fileName = listOfFiles[i].getName();
System.out.println(fileName);
doesFileExistInDb(fileName);
}
}