Skip to Main Content

Breadcrumb

Question and Answer

Chris Saxon

Thanks for the question.

Asked: September 20, 2017 - 7:27 am UTC

Last updated: May 14, 2019 - 1:13 pm UTC

Version: Version 4.0.1.14

Viewed 10K+ times! This question is

You Asked

Hi,
My question is
While compiling java source I am getting warning as :
JAVA SOURCE compiled
Warning: execution completed with warning
Failed to resolve object details

Code:
create or replace and compile java source named "DirTestList" 
as 
import java.io.*; 
import java.sql.*; 
 
 public class DirTestList
 { 
 public static void getList(String directory) 
 throws SQLException 
 { 
 File path = new File( directory ); 
 String[] list = path.list(); 
 String element; 
 
 for(int i = 0; i < list.length; i++) 
 { 
 element = list[i]; 
 #sql { INSERT INTO test_list (FILENAME) 
 VALUES (:element) }; 
 } 
 } 
 
 } 


Could you please assist on this.

Thanks

and Chris said...

Do you have a table called test_list with a filename column in your schema?

Because once that exists, it all works hunky-dory for me:

create or replace and compile java source named "DirTestList" 
as 
import java.io.*; 
import java.sql.*; 
 
 public class DirTestList
 { 
 public static void getList(String directory) 
 throws SQLException 
 { 
 File path = new File( directory ); 
 String[] list = path.list(); 
 String element; 
 
 for(int i = 0; i < list.length; i++) 
 { 
 element = list[i]; 
 #sql { INSERT INTO test_list (FILENAME) 
 VALUES (:element) }; 
 } 
 } 
 
} 
/
sho err

Errors for JAVA SOURCE CHRIS."DirTestList":

LINE/COL ERROR
-------- -----------------------------------------------------------------
0/0      Info: 1 warnings
0/0      ^
0/0      #sql { INSERT INTO test_list (FILENAME)
0/0      VALUES ( ...  ) ;
0/0      ^^^^^^^^^
0/0      INSERT INTO test_list (FILENAME)
0/0      DirTestList:16: Warning: Database issued an error: PL/SQL: ORA-00942: table or view does not exist

create table test_list ( filename varchar2(10) ); 

create or replace and compile java source named "DirTestList" 
as 
import java.io.*; 
import java.sql.*; 
 
 public class DirTestList
 { 
 public static void getList(String directory) 
 throws SQLException 
 { 
 File path = new File( directory ); 
 String[] list = path.list(); 
 String element; 
 
 for(int i = 0; i < list.length; i++) 
 { 
 element = list[i]; 
 #sql { INSERT INTO test_list (FILENAME) 
 VALUES (:element) }; 
 } 
 } 
 
} 
/
sho err

No errors.

Rating

  (5 ratings)

Is this answer out of date? If it is, please let us know via a Comment

Comments

A reader, September 20, 2017 - 10:18 am UTC

Hi,
Yes,we have test_list table in our schema still its giving error.

Thanks,
Chris Saxon
September 20, 2017 - 2:35 pm UTC

So what exactly do you see when you run "show errors" after creating the procedure?

(Like I have "sho err" after)

A reader, September 20, 2017 - 3:07 pm UTC

Hi,
Using show errors command
it gives below error:
JAVA SOURCE compiled
Warning: execution completed with warning
Failed to resolve object details

Even we have given grant JAVASYSPRIV to user ,still we are getting error
Connor McDonald
September 21, 2017 - 2:50 am UTC

Show us the WHOLE thing, just like we did, in SQL Plus.

We dont have a magical crystal ball :-)

Error in your code

A reader, June 18, 2018 - 4:27 am UTC

Kindly check the following:
1) Have you given permission to java source program to read files ?
Exec dbms_java.grant_permission( 'ADAM','SYS:java.io.FilePermission','/tmp/xml_inbound', 'read');

2) Try if the table mentioned exists or not

Naidu, December 13, 2018 - 9:07 am UTC

For me also getting same error can you please help me out.
Chris Saxon
December 13, 2018 - 1:36 pm UTC

Doing what?

Reason of failure not in answer

Peter de Vaal, May 14, 2019 - 12:38 pm UTC

The real reason the code does not work anymore is that on database 12.2 and later serverside SQLJ is not supported anymore. So the syntax with #sql should be replaced with other code. Perfect examples can be found at:
https://stackoverflow.com/questions/43385441/java-code-that-compiles-in-older-oracle-versions-gives-compile-error-in-oracle-1

Chris Saxon
May 14, 2019 - 1:13 pm UTC

Well, that depends which version of Oracle Database the OP was using!

Thanks for sharing though - I wasn't aware of this.

More to Explore

PL/SQL demos

Check out more PL/SQL tutorials on our LiveSQL tool.

PL/SQL docs

PL/SQL reference manual from the Oracle documentation library