0

i searched many ways but i didn't get the information about how to write the data to a file when call the database function (postgresql) in the java program.. please clarify me on this....

thanks in advance..

6
  • Which kind of database functions? Commented Jan 13, 2011 at 6:49
  • You don't need to use Java -- PostgreSQL has command line scripting that can write output to file directly. Commented Jan 13, 2011 at 6:52
  • just normal functions used in postgresql.. i am updating a table so i have to write the updation part to a log file . Commented Jan 13, 2011 at 6:54
  • Then why don't you try using java.io.FileWriter Commented Jan 13, 2011 at 7:10
  • just i want to update some times only and moreover the program is running in one machine and update the file in machine which is having the database . so i think this is the way.. please provide me the solution to solve this problem or any suggestions... Commented Jan 13, 2011 at 7:17

1 Answer 1

1

I assume you want the file to be written on the database server, not the application server (where the Java Program is running).

You need to implement a stored function in an untrusted language (like python or C). You would then call that function either from Java or from within the already existing function.

Here is an example that I found when googling for this:

CREATE FUNCTION makefile(text) 
RETURNS text AS 
$$
  o=open("/path/to/file")
  o.write(args[0])
  o.close()
  return "ok"
$$
LANGUAgE plpythonu;

Here is another one:

http://www.leidecker.info/pgshell/Having_Fun_With_PostgreSQL.txt

A (very) short description is also given here: http://archives.postgresql.org/pgsql-novice/2007-01/msg00010.php

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.