In the code below, I parsed all the filenames, then with it, I am trying to check the database to see if it exists in it or not. What am I doing wrong below? If so, can you let me know?
Also in execute command, I get an error saying listofFiles cannot be resolved to variable.
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);
}
}