开发者

Simulate Oracle SPOOL in Java

HI,

I am converting a shell script to a Java program. The shell scripts runs an sql stat开发者_如何学JAVAement and spool the file to an external text file. I want to simulate this in Java. (The output file must be in the exact same format as it was generated in running the comman in SQL+). Can anyone give me some guidelines such as formatting spacing ... for the file

Thanks


First, is this a fixed query, or an arbitrary one? If it's fixed, you'll have an easier time. Arbitrary queries will have to be run via dbms_sql, so you can return column attributes. That's messy.

Second, keep in mind that SQL*Plus formatting is controllable by settings in the client. Things like line length, page size, column widths, headers, etc. are all able to be changed from execution to execution.

That said, assuming it's a fixed query, then I'd:

  1. open a cursor for the query
  2. If there's data, print the column headers (including the '------' lines)
  3. loop through the cursor, printing each value for the record in proper format
  4. close the cursor

You should be able to format your output by examining the output from SQL*Plus and copying that.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜