简体   繁体   中英

Function invocation of postgresql database from java program

There is a Postgresql database with the following function stub

CREATE OR REPLACE FUNCTION net_train(terms text[], perceptron_id integer)
  RETURNS void AS
$BODY$begin
-- stub
end;$BODY$
  LANGUAGE plpgsql VOLATILE
  COST 100;
ALTER FUNCTION net_train(text[], integer)
  OWNER TO postgres;

How by a call in java to the program to transfer an array of terms (also it would be desirable to know as to transfer the second parameter) to this function? The input array of terms is written in

ArrayList<String> ProcessedTherms = new ArrayList<String>();

We used ibatis for mapping, but it should be similar:

Connection conn = ps.getConnection(); //ps is prepared statement
ArrayList arr = (ArrayList) param;
final Array sqlArray = conn.createArrayOf("integer", arr.toArray()); // we had integers, should be similar for String
ps.setArray(i, sqlArray);// i is position of parameter

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM