Problem java function

Hello guys,
I've done a java function to handle the fact that i move the decimal of a number to 2 instead of 3, 4, 5 or else.
For exemple, if i have in input the field 159, 7934 then i should have in output 159,79.
My problem is that it rounds the number !! So i have in output 159,8 !
Here's my function :
// Round the given input value to given number of decimals
// The result will be a floating point number (not integer value)
String zeroes = "00000000000000";
String numDec = numDecimals;
// To prevent a Divide by zero error default to 1 which would lead to a No-op
if (numDec.equals("") || numDec.equals("0"))
  numDec = "0";
String strFactor = "1" + zeroes.substring(0, Integer.parseInt(numDec));
int intFactor = Integer.parseInt(strFactor);
float i =Float.parseFloat(inputValue);
i = Math.round(i*intFactor);
i = i/intFactor;
return Float.toString(i);
Like you see, i'm putting in string format for the output because i am using a replacestring after in order to suppress the '.'
I think the problem come from that.
The solution would be to suppress the '.' in my UDF but i don't know how to code it in java.
Is someone knows please ?
Thanks by advance,
JP

Ok my UDF is now :
// Round the given input value to given number of decimals
// The result will be a floating point number (not integer value)
String zeroes = "00000000000000";
String numDec = numDecimals;
// To prevent a Divide by zero error default to 1 which would lead to a No-op
if (numDec.equals("") || numDec.equals("0"))
  numDec = "0";
//String strFactor = "1" + zeroes.substring(0, Integer.parseInt(numDec));
//int intFactor = Integer.parseInt(strFactor);
double i =Double.parseDouble(inputValue);
NumberFormat nf = NumberFormat.getNumberInstance();
nf.setMaximumFractionDigits(2);
String n = nf.format(i);
return n ;
BUT, when i put 2 digits, it still "rounding" my number even if i use a double or a float !
Nevertheless, when i want 3 digits, it still "rounding" !
Is it impossible to avoid the "round machine ?"

Similar Messages

  • Problem passing param to a java function from xslt

    HI all,
    A thousand thankyou's to any who can help me.
    Documentation is scarce, and I got to bed late last night. It has been a hard day of fruitless searching for a solution to this.
    Problem:
    Calling a named template in xsl using the with-param tag to pass in a parameter.
    attempting to call a java function, specifying that parameter as an argument.
    getting parse error:
    ERROR: 'Cannot convert argument/return type in call to method 'java.lang.String.new(java.util.Date)''
    sample code:
    calling the named template
              <xsl:call-template name="calc-age">
                   <xsl:with-param name="dob">
                        <xsl:value-of select="/FullRecord/Patient/dob"/>
                   </xsl:with-param>
              </xsl:call-template>the template itself
         <xsl:template name="calc-age">
              <xsl:param name="dob"/>          
             <xsl:variable name="date" select="java:util.Date.new()"/>
             <xsl:value-of select="java:toString($date)"/>
              <xsl:variable name="sdob" select="java:lang.String.new($date)"/>
         </xsl:template>          the error
    ERROR:  'Cannot convert argument/return type in call to method 'java.lang.String.new(java.util.Date)''
    FATAL ERROR:  'Could not compile stylesheet'
    javax.xml.transform.TransformerConfigurationException: Could not compile stylesheet
         at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl.newTemplates(TransformerFactoryImpl.java:824)
         at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl.newTransformer(TransformerFactoryImpl.java:613)does anyone know what is wrong here?
    And if they do, where I can find examples or a reference on how this is supposed to work?
    It's driving me mad!
    Thanks all!
    svaens
    Edited by: svaens on Apr 14, 2008 9:16 AM

    ok.
    What I had pasted was wrong, But I was it was only confused because I had tried quite a few different things to get it working, and had made a mistake somewhere along the way.
    HOWEVER!!!
    This code, I believe should work, (below) but doesn't.
    the error is different, but similar.
    The call to the template remains the same, but the template itself is now different.
    What is wrong with it?
    Do i need to convert a xml document string to a java string somehow?
    template:     <xsl:template name="calc-age">
              <xsl:param name="dob"/>          
             <xsl:variable name="sdob" select="java:lang.String.new($dob)"/>
             <xsl:value-of select="java:toString($sdob)"/>        
         </xsl:template>     the error:
    ERROR:  'Cannot convert argument/return type in call to method 'java.lang.String.new(reference)''
    FATAL ERROR:  'Could not compile stylesheet'To be more clear, I am translating XML via XSL which is transformed using Java 6, and the packages:
    import javax.xml.transform.Transformer;
    import javax.xml.transform.TransformerFactory;

  • Problem while calling java function from html

    when i tried to call a java function from html i'm getting an error
    object don't support this property.
    what could be the reason.
    This is my html.
    I got this from this forum only.
    My applet is accessing the system property "user.home".
    I ran it in IE
    <DIV id="dvObjectHolder">Applet comes here</DIV>
    <br><br>
    <script>
    if(window.navigator.appName.toLowerCase().indexOf("netscape")!=-1){ // set object for Netscape:
         document.getElementById('dvObjectHolder').innerHTML = " <object ID='appletTest1' classid=\"java:test.class\"" +
    "height=\"0\" width=\"0\" onError=\"changeObject();\"" +
              ">" +
    "<param name=\"mayscript\" value=\"Y\">" +
    "<param name=\"archive\" value=\"sTest.jar\">" +
    "</object>";
    }else if(window.navigator.appName.toLowerCase().indexOf('internet explorer')!=-1){ //set object for IE
         document.getElementById('dvObjectHolder').innerHTML = "<object ID='appletTest1' classid=\"clsid:8AD9C840-044E-11D1-B3E9-00805F499D93\"" +
              " height=\"0\" width=\"0\" >" +
              " <param name=\"code\" value=\"test.class\" />" +
         "<param name=\"archive\" value=\"sTest.jar\">" +
              " </object>"
    </script>
    <LABEL id="lblOutputText">This text will be replaced by the applet</LABEL>
    <BR>
    <input value="Javascript to java" type=button onClick="document.appletTest1.fromJavaScript()">

    I tried this example using the repy given to an earlier post.
    But its not working with me.
    What i did in addition was adding plugin.jar to classpath to import netscape.javascript.*;
    Let me add some more details
    1) I'll add the stack trace
    2) my java progrma
    3) batch file to sign the applet.
    1) This is the stack trace i don't know whether u will undertand this
    load: class test.class not found.
    java.lang.ClassNotFoundException: test.class
         at sun.applet.AppletClassLoader.findClass(Unknown Source)
         at java.lang.ClassLoader.loadClass(Unknown Source)
         at sun.applet.AppletClassLoader.loadClass(Unknown Source)
         at java.lang.ClassLoader.loadClass(Unknown Source)
         at sun.applet.AppletClassLoader.loadCode(Unknown Source)
         at sun.applet.AppletPanel.createApplet(Unknown Source)
         at sun.plugin.AppletViewer.createApplet(Unknown Source)
         at sun.applet.AppletPanel.runLoader(Unknown Source)
         at sun.applet.AppletPanel.run(Unknown Source)
         at java.lang.Thread.run(Unknown Source)
    Caused by: java.io.FileNotFoundException: C:\FastranJava\AppletObject\bin\test\class.class (The system cannot find the path specified)
         at java.io.FileInputStream.open(Native Method)
         at java.io.FileInputStream.<init>(Unknown Source)
         at java.io.FileInputStream.<init>(Unknown Source)
         at sun.net.www.protocol.file.FileURLConnection.connect(Unknown Source)
         at sun.net.www.protocol.file.FileURLConnection.getInputStream(Unknown Source)
         at sun.applet.AppletClassLoader.getBytes(Unknown Source)
         at sun.applet.AppletClassLoader.access$100(Unknown Source)
         at sun.applet.AppletClassLoader$1.run(Unknown Source)
         at java.security.AccessController.doPrivileged(Native Method)
         ... 10 more
    Exception in thread "Thread-5" java.lang.NullPointerException
         at sun.plugin.util.GrayBoxPainter.showLoadingError(Unknown Source)
         at sun.plugin.AppletViewer.showAppletException(Unknown Source)
         at sun.applet.AppletPanel.runLoader(Unknown Source)
         at sun.applet.AppletPanel.run(Unknown Source)
         at java.lang.Thread.run(Unknown Source)
    2) Java Program
    import netscape.javascript.*;
    import java.applet.*;
    public class test extends Applet
         private JSObject win;
         private JSObject outputLabel;
         private boolean buttonFromJavaClicked=false;
         checkJavaScriptEvent evt=new checkJavaScriptEvent();
         public void init()
              try
                   evt.start();
                   win=JSObject.getWindow(this);
                   outputLabel=(JSObject)win.eval("document.getElementById('lblOutputText')");
                   outputLabel.setMember("innerHTML", "<center><h1>From Init<br>Your Home directory" + System.getProperty("user.home") + "</h1></center>");
              catch(Exception e)
                   e.printStackTrace();
         public void fromJavaScript()
              buttonFromJavaClicked=true;          
         public void fromJavaScript2()
              System.out.println("Started Form JavaScript2");
              try
                   String strLbl="<center><h1>From JavaScript<br>Your Homedir:" + System.getProperty("user.home") + "</h1></center>";
                   outputLabel.setMember("innerHTML", strLbl);
              catch(Exception e)
                   e.printStackTrace();
         class checkJavaScriptEvent extends Thread
              public void run()
                   while(true)
                        if(test.this.buttonFromJavaClicked)
                             System.out.println("OK buttonfromjava is true");
                             test.this.buttonFromJavaClicked=false;
                             fromJavaScript2();
                        try
                             Thread.sleep(3000);
                        catch(Exception e)
                             e.printStackTrace();
    3) Batch file
    del *.cer
    del *.com
    del *.jar
    del *.class
    javac -classpath ".;C:\Program Files\Java\jre1.5.0_06\lib\plugin.jar" test.java
    keytool -genkey -keystore harm.com -keyalg rsa -dname "CN=Harm Meijer, OU=Technology, O=org, L=Amsterdam, ST=, C=NL" -alias harm -validity 3600 -keypass password -storepass password
    jar cf0 test.jar *.class
    jarsigner -keystore harm.com -storepass password -keypass password -signedjar sTest.jar test.jar harm
    del *.class

  • The problem of function-based reuse

    I read the quoted text as follows from a book authored by a Microsoft developer. I googled and found a lots of quotes of it, but did not find any explanation.
    ============
    With languages like C, the basic unit of reuse is the function. The problem with function-based reuse is that the function is coupled to the data it manipulates. and if the data is global, a change to benefit one function in one reuse context damages another function used somewhere else.
    ============
    C uses libraries widely,which is of function-based reuse. Can anybody kindly give me a scenario when this problem happens?
    Java is typically object-based reuse, and I admit that my question is not a Java one. But I feel it would help to understand more about the concept or benefits of design of Java language. So, thank you to allow me to post this question here,
    Edited by: 799160 on Sep 30, 2010 12:38 PM
    Edited by: 799160 on Sep 30, 2010 12:57 PM

    This is what I got out of reading the quote you posted:
    I suppose something like the following could happen:
    You (being a general person) have been given a class to modify. You look at the code for the first time and it has a bunch of methods and some class variables in it. Some of the methods use the class variables. How can you be sure if you change the functionality to change a class variable in one method won't affect the other methods when they are used? This problem can be solved by learning what everything does, how it interacts and the correct way to use it. But then again, if you don't think about it and just make changes...Oops!
    Perhaps another abstract example would make sense:
    Imagine a calculator that could be used by 2 people at the same time? I bet it'd come up with some funny answers :)
    I wrote up a short example of this, hopefully it makes some sense:
    public class SuperBigProgram
         private int globalVar;
         public static void main ( String[] args )
              new SuperBigProgram();
         public SuperBigProgram()
              System.out.println("I'm a super big program.");
              globalVar = 0;
              //Let's pretend these series of events occur during the program:
              doItHighChanceActivity(); //1
              doItHighChanceActivity(); //2
              doItHighChanceActivity(); //3
              //Whoops super rare event occured!
              doesNotHappenALot();
              doItHighChanceActivity(); //4????    but is really 5.
          * This happens A LOT!
         private void doItHighChanceActivity ()
              superUtilityMethod();
              System.out.println("globalVar: " + globalVar);
          * This utility method does some awesome utility stuff for our Super Big Program.
          * This changes some global data.
         private void superUtilityMethod()
              globalVar++;
          * This does not happen a lot, if at all.
         private void doesNotHappenALot()
              //Hey I don't happen a lot but I'm reusing this really cool utility method that contains global data...
              //Code reuse for the win!
              superUtilityMethod();
    }Here is the output:
    I'm a super big program.
    globalVar: 1
    globalVar: 2
    globalVar: 3
    globalVar: 5
    Edited by: kilosi on Sep 30, 2010 1:22 PM

  • How to use  Advance java function in graphical mapping in XI 2.0?

    Hi,
    currently I am using a simple java function to make an RFC call to R3 system.
    I want to avoid making connection for each lookup. Instead I want to make a single connection for whole message queue and get the corresponding values in some array or container object.
    please suggest a solution.
    I think this is possible using Advance java function, but I am not able to find any example on using Advance java function at help.sap.com.
    thaks in advance.

    Hi!!!
    I'm not sure if I understood you well.
    Do you want to preload some data into your structures in the memory and keep them there so you don't need to make a new connection during processing the whole message or every message?
    In my opinion you can cache some data during processing a message, but it's impossible to cache some data between processing messages.
    If you write your java mapping or you use graphical mapping (even with user-defined function), then you have a java class. The problem is that XI 2.0 reloads this class during processing every message, so even if you load some data from your data source into your structures in the memory, this data will be lost after reloading your mapping class.
    Regards,
    Andrzej Filusz

  • ABAP Calling JAVA Function or Method

    Hi Friend,
    I need help in how to proceed using  ABAP  and Call JAVA Function . I know that  we need to use RFC enabled Function modules. I was able to connect  using JAVA Connector which was provided by SAP For communicating with JAVA Apps. The approach for connecting the JAVA to SAP is working fine.  But I  have browsed through various website but failed to find any information.Now i am looking forward to help from you friends to solve my problems .
    The Requirement is mentioned below:-
      1. Prerequiste for SAP ABAP calling a third Party software which is working in JAVA Platform (like any middle ware which might be hardware or software).
      2. Sample Code  like calling a Text  ' Hello  to the world  calling JAVA from ABAP'.
      3. Steps and process so that it would be helpful.
    Timely help would be appreciated.
    Rajiv Christopher.

    1.Middleware is JCO RFC provider it comes with SAP so no need any third party Adapter.
    2.
    " The ECHOTXT parameter should contain the text of REQUTXT.Information on
    " calling the function module should be returned in RESPTXT, indicating, for
    " example, in which system and when the function module call was processed.
    data:ECHOTEXT type SY-LISEL,
         RESPTEXT type SY-LISEL.
    CALL FUNCTION 'STFC_CONNECTION' DESTINATION '<Your JCO destination name>' " which one you have developed in SM59 as TCP/IP
      EXPORTING
        requtext       = 'ABAP Calls JAVA'
    IMPORTING
       ECHOTEXT       = ECHOTEXT
       RESPTEXT       = RESPTEXT.
    if sy-subrc = 0.
      WRITE:/'---------------------------------------------------------------------'.
      WRITE: / 'establish a link to the ABAP application server with logon data'.
      WRITE:/'---------------------------------------------------------------------'.
      write:/ ECHOTEXT .
      else.
          WRITE:/'---------------------------------------------------------------------'.
      WRITE: / 'Not establish a link to the ABAP application server with logon data'.
      WRITE:/'---------------------------------------------------------------------'.
      endif.
    Check the sample code and Let me know will you get ECHOTEXT ?
    Kanagaraja L
    Edited by: Kanagaraja  Lokanathan on Jan 6, 2010 1:27 PM

  • Call Java functions in a C DLL

    Hi,
    I am develop a dynamic link library in C on AIX that will internally call java functions using JNI. This libaray will be finally used by other C Executable.
    There is only one function in C code i.e. Connect. This function internally use JNI and call java functions. Now while compiling I am facing problems. I think that there is some problem with my makefile.
    The make file is given hereunder:
    JAVA_HOME = /usr/java14
    JAVA_INC = $(JAVA_HOME)/include
    CC = cc
    LD = cc
    # Flags to create a dynamic library.
    DYNLINKFLAGS =  -G -ostdlib -bnoentry -bM:SRE -brtl -bE:Interface.exp
    # files removal
    RM = rm -f
    #------------------------------------- Libs -----------------------------------#
    JAVALIBS      = -L$(JAVA_HOME)/jre/bin/classic/
    LIBS            = -ljvm -lpthread  -lxnet -lnsl -lm -ldl
    #-------------------------------- Dependency rules---------------------------#
    # shared library files
    LIB_FILES = Interface.a
    #-------------------------------------OBJs-------------------------------------#
    # shared libraries object files
    LIB_OBJS    = Interface.o
    all: $(LIB_FILES)
    # create our librarys
    Interface.a: Interface.o
         $(LD) $(DYNLINKFLAGS) $(JAVALIBS) $(LIBS) $(LIB_OBJS) -o $@
    # compile C source files into object files.
    %.o: %.c
         $(CC) $(DYNLINKFLAGS) -L$(JAVA_INC) -c $<
    # clean everything
    clean:
         $(RM) $(LIB_OBJS) $(LIB_FILES)
    # clean the library's object files only
    cleanlibobjs:
         $(RM) $(LIB_OBJS)Now the problem is that the size of the Interface.a file is very small only 552 bytes. whereas the size of Interface.o file is 34428. Which clearly indicates that the problem is with the Interface.a file i.e during linking.
    Can any body help me to figure out the problem.
    Regards,
    Ahmad Jalil Qarshi

    I guess, you are better off to ask this question in a C forum. This is a Java forum, you know.

  • Calling JAVA Functions from XSLT

    Hi,
    I am trying to invoke a Java Extension Function from a XSLT. I added both the class file and the XSLT file to a folder, then zipped the entire folder and uploaded into the Archive for my Interface MApping.
    The CLASS gets loaded but the runtime engine gives an error when calling the JAVA Function.
    Here is what it says:
    Creating mapping sequence with 2 steps. --- Creating Java mapping Deliveries/stringHandler --- Creating mapping sequence with 2 steps. --- Creating XSLT mapping Deliveries/test1 --- Using MappingResolver with context URL /sapmnt/XD1/global/xi/mapping/http%3A%2F%2Fwolterskluwer%2Ecom%2Fxi%2F wk_midas_deliveries%2Ftest/cd2e6820267511d9cb52c3c5143c3524/ --- Loaded class Deliveries.stringHandler --- com.sap.aii.ibrun.server.map.MappingRuntimeException: at com.sap.aii.ibrun.server.map.MappingRuntimeException.code_STYLESHEET_OR_CLASS_NOT_FOUND(MappingRuntimeException.java:91) at com.sap.aii.ibrun.server.map.RUMappingJava.instantiate(RUMappingJava.java:168) at com.sap.aii.ibrun.server.map.RUMappingJava.execute(RUMappingJava.java:41) at com.sap.aii.ibrun.server.map.RUSequence.execute(RUSequence.java:50) at com.sap.aii.ibrun.server.map.RURunner.run(RURunner.java:58) at com.sap.aii.ibrun.server.map.RUManager.run(RUManager.java:66) at com.sap.aii.ibrun.sbeans.map.MappingRequestHandler.handleRequest(MappingRequestHandler.java:67) at com.sap.aii.ibrun.sbeans.map.MappingServiceImpl.processFunction(MappingServiceImpl.java:83) at com.sap.aii.ibrun.sbeans.map.XMappingServiceObjectImpl0.processFunction(XMappingServiceObjectImpl0.java:24) at com.sap.aii.ibrun.sbeans.map.MappingServiceKey.processFunction(MappingServiceKey.java:10) at java.lang.reflect.Method.invoke(Native Method) at com.inqmy.services.rfcengine.RFCDefaultRequestHandler.invokeBean(RFCDefaultRequestHandler.java:83) at com.inqmy.services.rfcengine.RFCDefaultRequestHandler.handleRequest(RFCDefaultRequestHandler.java:50) at com.inqmy.services.rfcengine.RFCJCOServer.handleRequest(RFCJCOServer.java:69) at com.sap.mw.jco.JCO$Server.dispatchRequest(Unknown Source) at com.sap.mw.jco.rfc.MiddlewareRFC$Server.nativeListen(Native Method) at com.sap.mw.jco.rfc.MiddlewareRFC$Server.listen(Unknown Source) at com.sap.mw.jco.JCO$Server.listen(Unknown Source) at com.sap.mw.jco.JCO$Server.run(Unknown Source) at java.lang.Thread.run(Thread.java:513) --
    Any help or suggestions to solve this problem would be greatly appreciated.
    Thanks
    A

    Hi,
    Thanks for looking into this.
    1. I have verified that the path in the zip file is correct i.e com/sap/test/stringHandler.class
    2. test1.xsl is in the root folder i.e No path.
    3. I see the Message in the stacktrace saying "Loaded Class com/sap/test/stringHandler.class " but after that I get a runtime MApping Error and it says "CLASS_NOT_FOUND".
    Can you please tell me why is this happening?
    Thanks
    A

  • Java function activity agent fails

    Hello,
    Trying to run workflow java function activity agent ends with dr. Watson. Environment:
    OS: NT40 sp 6
    DB: 8.1.7.0.0
    JRE: 1.1.8
    Anybody came across this or is this a known problem? Please share your findings.
    Thank you.
    Anatoliy

    Sorry,
    The problem was with the wrong jar file.

  • 9iAS  java functions are not working

    Dear All.
    I’m using oracle 9iAS Release 9.2.0.1.0 and JServer Release 9.2.0.1.0. I’m using java functions (eg. Array, pop, push method and trim function) in my JavaScript section.
    But these functions are not working. When run the page it work up to that function and stuck. Functions are written properly.
    I would be much-appreciated .if you could help me to solve this problem..
    Regards,
    Nish

    Are you sure you uncommented and changed jvm.include.CLASSPATH=1
    in the jvm12.conf when you added your classpath there?
    The preferred way to do this would be to create a .war and deploy it instead. Then you can put your beans in the WEB-INF/classes directory and the application wont have conflict problems if you decide to create virtual servers later.

  • Access session variable in Java Function in JSP

    Hi Experts !!
    I am developing an application using STRUTS MVC...
    Very sorry if u have problem understanding my question, i ll try to improve... and sorry if i can't post codes here
    Basic question is ....
    I want to open a word document on pageLoad of JSP, the word document is not a single document, there is a form in which there is a "name" and "template" whenever user clicks on a button there is one action attached to it which creates a copy of that template in a different folder.. on the next page OnLoad i want to open that particular document. for that i have created a variable and also have set in the session, just want to access it in the below code.
    I have a formbean in which i have a variable, the scope is session, that variable i have put it in session also. but i want to access that variable in a "java function" in JSP so that "onLoad" page that function should work.
    JSP---
    <script type="text/javascript">
    function openDocument() {
    var w = new ActiveXObject("Word.Application");
    var docText;
    var obj;
    var a;
    if (w != null) {
    w.Visible = true;
    obj = w.Documents.Open(I HAVE TO ACCESS THAT VARIABLE HERE);
    </script>
    FORMBEAN----
    public class CreateSOWFormBean extends ActionForm {
    private String workflowName;
    private String comment;
    private String sowTemplate;
    private String sowFileCreated;
    public String getSowFileCreated() {
    return sowFileCreated;
    public void setSowFileCreated(String sowFileCreated) {
    this.sowFileCreated = sowFileCreated;
    sowFileCreated is the variable that i have accessed in session and that value i have to pass in that function in JSP....
    I am aware of something like
    obj = w.Documents.Open(<%'sowFileCreated'%>);
    but i m not sure how to write....
    Plz help.....

    If you're working under a framework like struts you should definitely be using JSTL tags rather than scriptlet code to access variables within the page. With JSTL code <% codes can be almost entirely avoided.
    To transfer a value from a Servlet to a JSP don't use a session variable, use a request attribute. Session variables should only be used when values have to survive from one transaction to another.
    You can write something like:
    obj = w.Documents.open('<c:out value="${openURL}"/>');in the Javascript portion of your JSP.
    Just beware of potential problems with quotes. The coresponding code in the Servlet would be like:
    request.setAttribute("openURL", openUrl);

  • Java function calls from JSTL

    I'm working on an application where the original designers have put an escape character preceding every single quote when entering data into a DB.
    Ex: A user enters O'Riely, and it gets put into the DB as O\'Reily.
    The problem is that when using JSTL to retrieve the data, the escape character remains. I've got a Java function that removes this escape character for some dynamically created pages and tables, however I'm not sure how to remove the escape character from simple JSTL retrievals.
    Does anyone have an idea how this can be done? Or if it's possible to call a Java function from a JSTL call in a JSP?
    Thanks, in advance.

    That's likely just a dummy function to avoid SQL injections.
    At the data layer, rather use PreparedStatement [1] instead of Statement to insert unchanged data. Sun has a nice tutorial on that [2]. Or use an ORM like Hibernate [3] to persist data in DB.
    [1] http://java.sun.com/j2se/1.5.0/docs/api/java/sql/PreparedStatement.html
    [2] http://java.sun.com/docs/books/tutorial/jdbc/basics/prepared.html
    [3] http://www.hibernate.org

  • Java functions with Oracle 10g

    I have browsed through other related message threads on this forum and it seems that the general recommendation is to develop stored procedures and functions using PL/SQL.
    I need to implement a set of functions that perform date related processing and are self contained (no SQL code or calls). For this I could reuse some Java methods that I have successfully used in an Apache Derby database. In this situation what is your experience related to performance of Java functions compared to PL/SQL? Does the effort of rewriting this code in PL/SQL make sense?

    I made some changes on the class posted by to solve the encoding problems with CLOBs.
    So here is the result of my job.
    import java.sql.SQLException;
    import oracle.sql.*;
    import java.io.*;
    import java.util.zip.InflaterInputStream;
    import java.util.zip.DeflaterOutputStream;
    * A simple class for LOB compression and decompression in Oracle Database.
    * Will work in 8i and better.  Use utl_compress from 10g onward.
    public class CompressionUtility {
         private static void pipeStreams( InputStream inStream, OutputStream outStream, int bufferSize) throws IOException {
              //System.out.println("PIPE -");
              byte[] buffer=new byte[bufferSize];
              int cnt;
              while ((cnt=inStream.read(buffer))!=-1) {
                   outStream.write(buffer,0,cnt);
         private static void pipeStreams( Reader inStream, Writer outStream) throws IOException {
              //System.out.println("PIPE Reader-Writer");
              int val = 0;
              while ( (val = inStream.read()) != -1 ) {
                   outStream.write(val);
         private static void pipeStreams( Reader inStream, OutputStream outStream) throws IOException {
              //System.out.println("PIPE Reader-");
              int val = 0;
              while ( (val = inStream.read()) != -1 ) {
                   outStream.write(val);
        private static void pipeStreams( InputStream inStream, Writer outStream) throws IOException {
              System.out.println("PIPE -Writer");
              int val = 0;
              while ( (val=inStream.read()) != -1 ) {
                   outStream.write(val);
    * Compresses the CLOB into BLOB
    * @param clob the source CLOB (plain text)
    * @param blob the target BLOB (will hold compressed binary data) it should be
    * an empty BLOB retrieved for example with dbms_lob.createtemporary(l_blob,true);
    * @throws Exception mostly I/O exception if ever
         public static void compress(CLOB clob, BLOB blob) throws IOException, SQLException {
              //System.out.println("Compressione C->B");
              Reader in=clob.getCharacterStream();
              Writer z=new OutputStreamWriter(new DeflaterOutputStream(blob.getBinaryOutputStream()));
              DeflaterOutputStream z = new DeflaterOutputStream(blob.getBinaryOutputStream());
              int val = 0;
              while ( (val=in.read()) != -1 ) {
                   z.write(val);
              pipeStreams(in, z);
              in.close();
              z.close();
    * Decompresses the BLOB into CLOB
    * @param blob the source BLOB (compressed binary data)
    * @param clob the target CLOB (will hold plain text) it should be an empty CLOB
    * retrieved for example with dbms_lob.createtemporary(l_clob,true);
    * @throws Exception mostly I/O exception if ever
        public static void decompress(BLOB blob, CLOB clob)
          throws IOException, SQLException {
               //System.out.println("Decompressione B->C");
            Writer out=clob.getCharacterOutputStream();
            Reader z=new InputStreamReader(new InflaterInputStream(blob.getBinaryStream()));
              InflaterInputStream z = new InflaterInputStream(blob.getBinaryStream());
            int val = 0;
              while ( (val=z.read()) != -1 ) {
                   out.write(val);
            pipeStreams(z, out);
            z.close();
            out.close();
    * Compresses the BLOB into BLOB
    * @param slob the source BLOB (plain binary data)
    * @param blob the target BLOB (will hold compressed binary data) it should be
    * an empty BLOB retrieved for example with dbms_lob.createtemporary(l_blob,true);
    * @throws Exception mostly I/O exception if ever
        public static void compress(BLOB slob, BLOB blob)
          throws IOException, SQLException {
               //System.out.println("Compressione B->B");
            InputStream in=slob.getBinaryStream();
            DeflaterOutputStream z=new DeflaterOutputStream(blob.getBinaryOutputStream());
            pipeStreams(in, z, blob.getBufferSize());
            in.close();
            z.close();
    * Decompresses the BLOB into CLOB
    * @param blob the source BLOB (compressed binary data)
    * @param slob the target CLOB (will hold plain binary data) it should be an
    * empty CLOB retrieved for example with dbms_lob.createtemporary(l_blob,true);
    * @throws Exception mostly I/O exception if ever
        public static void decompress(BLOB blob, BLOB slob)
          throws IOException, SQLException {
               //System.out.println("Decompressione B->B");
            OutputStream out=slob.getBinaryOutputStream();
            InflaterInputStream z=new InflaterInputStream(blob.getBinaryStream());
            pipeStreams(z, out, blob.getBufferSize());
            z.close();
            out.close();
    }The main problem was with the getAsciiStream() function that has to be replaced by getCharacterStream().

  • Call a Java Function From Abap

    Hi, I need to call a java function from ABAP,  I have a WAS 640 to deploy the module.
    I have found this tutorial...
    [ABAP calls Java via RFC|/people/thorsten.franz3/blog/2008/11/21/abap-calls-java-via-rfc-1-introduction]
    The problem is that it uses a newer version of WAS and it implements EJB 3.0 wich only works on Java 5, but my WAS has java 1.4.2.
    Anyone knows how to adapt this Blog to a WAS 640 version ?
    Or Perhaps there is another way of doing this, maybe publishing my function as a web service.
    Regards.
    Mariano.

    Why don't you expose your Java functionality as a Web Service and consume it in ABAP program. That should be much easier and the web service can be used in other places as well.
    Best regards,
    Ritesh Chopra

  • Create custom java function in graphical mapper for Global use?

    I created a java function (remove leading zeros in string field) in the graphical tool.
    The problem custom function is at local map level only.
    How can i make custom java function global for use in all SWC/namespaces/interfaces.
    Can this be done with XI 3.0 SP 13?  Any suggestions on how to do this.
    Many Thanks,

    HI William
       Check out this link...
    http://help.sap.com/saphelp_erp2005/helpdata/en/e2/e13fcd80fe47768df001a558ed10b6/frameset.htm
    http://help.sap.com/saphelp_erp2005/helpdata/en/22/e127f28b572243b4324879c6bf05a0/frameset.htm
    Cheers:-)
    Mithlesh

Maybe you are looking for