× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.


  • Subject: RE: Tricks to get output from Java to ODBC caller?
  • From: Geert Van Landeghem <gvl@xxxxxxxxxxxxxx>
  • Date: Mon, 14 Feb 2000 09:15:58 +0100

Luther,

You can use System.setOut(PrintStream) and System.setErr(PrintStream) to
redirect
the output(&erros) generated by your java program to a PrintStream. 

I've created a small example in which the output of a program is written
to a text file. The output could also be saved to a physical file which
is read using JDBC or ODBC. I tested this program on our AS/400 and it
works fine:

 import java.io.*;

 public class Logging {

   public Logging() {
   }

   public static void main(String[] args) {
     Logging logging = new Logging();
     PrintStream ps=null;
     PrintStream op=null;
     FileOutputStream fos=null;
     FileReader fr=null;

     System.out.println("Hello...");
     // Saving the original Output PrintStream
     op = System.out;
     // Creating the output log file
     try {
       fos=new FileOutputStream("Test.log");
       ps=new PrintStream((OutputStream)fos);
     }
     catch(Exception e1) {
       System.out.println("Logging file not created!");
     }
     // Setting the System Output to the log file
     System.setOut(ps);
     // Generating output
     System.out.println("Log messages:");
     System.out.println("Log line 1");
     System.out.println("Log line 2");
     // END OF PROGRAM
     try{
       fos.flush();
       fos.close();
     }
     catch(Exception e2) {
       System.out.println("Error closing log file!");
     }

     // Printing the contents of the log file
     // Reset of System.out
     System.setOut(op);
     // Reading the log file
     try {
       BufferedReader br=new BufferedReader(new FileReader("Test.log"));
       String msg=null;
       while ( (msg=br.readLine()) != null) {
         System.out.println("Logged messages : " + msg);
       }
       br.close();
     }
     catch(Exception e3) {
       System.out.println("Error reading the log file!");
     }
     // Wait for keyboard input to end the program
     try {
       System.in.read(new byte[1]);
     }
     catch(Exception e4) {
       System.out.println("Error waiting for keyboard input!");
     }
     System.exit(0);
   }
 }


-----Original Message-----
From: Luther Ananda Miller [mailto:luther.miller@HYPERE.COM]
Sent: donderdag 10 februari 2000 13:02
To: L-JAVA400@midrange.com
Subject: Tricks to get output from Java to ODBC caller?


We have put a call to a Java program into a CL program in order to call it
from ODBC (actually, we may have been able to bypass the CL program
altogether, but that is not important) using CALL QSYS.QCMDEXC.

Does anyone know a way to get output from a Java program? We would like to
run the java program and get some output from it to return to the calling
application. The caller would use ODBC or JDBC (solution must support both
in this case, not just JDBC) and stored procedures with input/ouput params.

I would be able to write a C stored procedure which in turn could call the
java program, but I also do not know how to get java output to a C program.

Any ideas?

luther.miller @ hypere.com


+---
| This is the JAVA/400 Mailing List!
| To submit a new message, send your mail to JAVA400-L@midrange.com.
| To subscribe to this list send email to JAVA400-L-SUB@midrange.com.
| To unsubscribe from this list send email to JAVA400-L-UNSUB@midrange.com.
| Questions should be directed to the list owner: joe@zappie.net
+---
+---
| This is the JAVA/400 Mailing List!
| To submit a new message, send your mail to JAVA400-L@midrange.com.
| To subscribe to this list send email to JAVA400-L-SUB@midrange.com.
| To unsubscribe from this list send email to JAVA400-L-UNSUB@midrange.com.
| Questions should be directed to the list owner: joe@zappie.net
+---

As an Amazon Associate we earn from qualifying purchases.

This thread ...


Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.