当前位置: 动力学知识库 > 问答 > 编程问答 >

sqlplus - Pass parameters in a sql script via java

问题描述:

I have a sqlplus script which requries some external parameters. Those parameters should come from an array present in the java code. I want to pass those values to the sql script but don't know how. Please guide me.

MY sqlplus file is as shown below

SET ECHO OFF

SET HEADING OFF

SET FEEDBACK OFF

SET VERIFY OFF

SET DEFINE ON

SET TRIMSPOOL ON

SET NEWPAGE NONE

SET TERMOUT OFF

spool &3/&2..&1..fn

select text

from dba_source

where name = '&2'

and type = 'FUNCTION'

and owner = '&1'

order by line

/

spool off

exit;

The java code I am using to execute this file in unix server is shown below.

try {

String line;

Process p = Runtime.getRuntime().exec(

"sqlplus -L user/[email protected] @" + sqlFilePath);

BufferedReader input = new BufferedReader(new InputStreamReader(

p.getInputStream()));

while ((line = input.readLine()) != null) {

System.out.println(line);

}

input.close();

p.destroy();

} catch (Exception err) {

err.printStackTrace();

}

Please guide me how can I pass a string present in the java code to execute this sqlplus script in unix server.

网友答案:

Try using a template engine like http://freemarker.org/. It is very generic, but should not be so difficult to use.

分享给朋友:
您可能感兴趣的文章:
随机阅读: