Xplosio Xplosio - 5 months ago 20
Java Question

Succes with compiling Error JVM Oracle Database Move Data

I have a Data in a specific folder. I only know the id. But the name of the data contain more then an ID, because of that I am using "listFiles". For security reason only the database can enter the file system, because of that I want to upload the java class into my oracle. But my Oracle DB always says that it success compiling with Error and I don't know why.

Here is my code:

CREATE OR REPLACE AND RESOLVE JAVA SOURCE NAMED MOVEFILE as `import java.io.*`;
public class MOVEFILE {
/**
* Eigentliche Methode zum Verschieben
*/
public static int moveFile(String orgPath, String gewPfad, String dateiID) {
File folder = new File(orgPath);
File[] listOfFiles = folder.listFiles(new FilenameFilter(){
@Override
public boolean accept(File folder, String name){return name.toLowerCase().contains(dateiID);}});
String orgDatei = listOfFiles[0].toString();
File org = new File(orgDatei);
File gew = new File(gewPfad);
if (!org.exists())
return 0;
if (gew.exists())
return 0;
if (copyFile(orgDatei, gewPfad) == 1)
if (deleteFile(orgDatei) == 1)
return 1;
return 0;
}


I have methods
copyFile
and
deleteFile
. When I compile them without
moveFile
it compiles successfully.

Can you help me? Sorry for my bad english. If you have any question I will answer them as soon as I can. Thank you :)

Answer

Berger got it right in the comments, I think.

You cannot reference dateiID in the anonymous inner class you define for listOfFiles, unless you make dateiID final.

Also, you don't need single quotes around the import line.

You could have discovered this for yourself by asking the database what the problem was, like so:

select * 
from dba_errors 
where name = 'MOVEFILE' 
order by sequence;