0 Replies Latest reply: Apr 15, 2011 1:14 PM by user502964 RSS

    Java Print Service API in Java Stored Procedure (Linux / Cups)

    user502964
      Hello teachers!
      I'm having a problem to use a Java API for printing via the service Cups on Linux OS.
      It turns out that the JAVA API (PrintServiceLookup) can not return the printers installed on the Linux CUPS service.
      I found some people with the same problem but all without solution.
      Java Print Service API in Java Stored Procedure (Linux)

      Information on the Environment:
      SO: Linux Read Hat ES 5.3 (64 bits / XEON quade core)
      Oracle: 10.2.0.4

      Code to test:

      CREATE OR REPLACE AND RESOLVE JAVA SOURCE NAMED "ListPrinters"
      AS import javax.print.*;
      import javax.print.attribute.*;
      import javax.print.attribute.standard.*;

      public class ListPrinters {
      public static String AvailablePrinters(){
      String strList;
      PrintService[] pservices =PrintServiceLookup.lookupPrintServices(null,null);
      if (pservices.length > 0 )
      strList = pservices[0].getName();
      else
      strList = "No printers found";
      return strList;
      }

      public static String listprinters() throws Exception {
      String listofprinters;
      try {
      SecurityManager sm = System.getSecurityManager();
      if (sm != null) sm.checkPrintJobAccess();
      }
      catch (SecurityException ex) {
      System.err.println("Sorry. Printing is not allowed.");
      }

      listofprinters = AvailablePrinters();
      return listofprinters;
      }
      }
      /

      CREATE OR REPLACE
      FUNCTION get_printer_test RETURN VARCHAR2 IS
      LANGUAGE JAVA
      NAME 'ListPrinters.listprinters() return String';
      /

      SELECT get_printer_test FROM DUAL
      /


      Thanks