If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > PostgreSQL > PostgresSQL 8.4 PL/Java IO access issue.

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 09-04-11, 06:25
marc_ marc_ is offline
Registered User
 
Join Date: Aug 2011
Location: Glasgow, UK
Posts: 36
Arrow PostgresSQL 8.4 PL/Java IO access issue.

Hello,

I am attempting to create a simple PL/Java function that checks where a file exists or not but I am getting an IO error. Are there any security switches I need to set when creating the PL/Java function or is there anything else I am missing?

Code below...

Many thanks,
Marc :-)

Code:
//Java Code 
public class FileExists 
{ 
     public static boolean checkFile (String input) throws Exception 
  { 
  String errorMessage; 

  try 
  { 
   // Check file exists and pass the value back thru the OUT paramenter 

   File f = new File(input); 

   return (f.exists()); 

  } 
  catch (SecurityException ioe) 
  { 
   errorMessage = ioe.getMessage(); 
   throw new Exception( errorMessage + " FAILED" ); 
  } 
 } 
} 


-- PL/Java Wrapper Fuction 
CREATE FUNCTION fileexists(character varying) RETURNS boolean 
    LANGUAGE java 
    AS $$FileExists.checkFile(java.lang.String)$$; 

--Results 
mydb=# select fileexists('/home/postgres/myfile.txt'); 
ERROR:  java.lang.Exception: read on /home/postgres/myfile.txt FAILED
Reply With Quote
  #2 (permalink)  
Old 09-04-11, 08:19
marc_ marc_ is offline
Registered User
 
Join Date: Aug 2011
Location: Glasgow, UK
Posts: 36
Found out from nabble forum users that the language has to be javaU (untrusted) for IO access:


Code:
mydb=# CREATE OR REPLACE FUNCTION fileexists(character varying) RETURNS boolean
mydb-#    LANGUAGE javaU
mydb-#    AS $$FileExists.checkFile(java.lang.String)$$;
CREATE FUNCTION
mydb=# select fileexists('/home/postgres/myfile.txt');
 fileexists 
------------
 t
(1 row)

mydb=# select fileexists('/home/postgres/myxxyfile.txt');
 fileexists 
------------
 f
(1 row)
Reply With Quote
Reply

Tags
java, pl/java, postgres, postgresql

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On