How to use host variable in Java?

How do I use host variable in java? I am getting SQL code of -404 and description of SQL code is The UPDATE or INSERT statement specifies a String that is too long column-name SQLSTATE=22001. Below is my code:
* i n s e r t M e s s a g e
* insertMessage: This method will retrive detail message and other fields for
* selected item from screen1.
public final Collection insertMessage(String businessId,String messageNumber,String messageType,
String messageTitle,String printStyle,String statusIndicator,
String approverId,String lastUpdateId,String longMessage) {
MessageTransport msi = new MessageTransport();
PreparedStatement ps = null;
Connection connection = null;
MessageTransport msi1 = new MessageTransport();
PreparedStatement ps1 = null;
Connection connection1 = null;
ArrayList list = new ArrayList();
try {
if (businessId != null) {
businessId = businessId.trim();
if (messageNumber != null) {
messageNumber = messageNumber.trim();
if (messageType != null) {
messageType = messageType.trim();
if (messageTitle != null) {
messageTitle = messageTitle.trim();
if (printStyle != null) {
printStyle = printStyle.trim();
if (statusIndicator != null) {
statusIndicator = statusIndicator.trim();
if (approverId != null) {
approverId = approverId.trim();
if (lastUpdateId != null) {
lastUpdateId = lastUpdateId.trim();
if (longMessage != null) {
longMessage = longMessage.trim();
int len = longMessage.length();
if (len > 254) {
int constant = 254;
int k = len % constant; //k will hold value that has number of loops including initial insert.
k = k - 1; //this is for total number of loop.
int j = len / constant; //this will have remainder if any to insert rest of longmessage.
System.out.println("Display remainder: " + k);
System.out.println("Display divisible: " + j);
System.out.println("Display Length of longMessage: " + len);
StringBuffer sql = new StringBuffer();
sql.append("INSERT INTO " + MESSAGE_TBL + " ( MT_BUS_ID,MT_MSG_NBR,MT_MSG_TYPE,MT_MSG_TITLE,MT_PRINT_STYLE,MT_APV_STATUS,MT_APV_ID,MT_APV_DT,MT_APV_TM,MT_LAST_UPDATE_ID,MT_LAST_UPDATE_DT,MT_LAST_UPDATE_TM,MT_MSG_TXT ) VALUES ");
sql.append("(");
sql.append("'");
sql.append(businessId).append("'");
sql.append(",").append(messageNumber);
sql.append(",").append("'I'");
sql.append(",").append("'").append(messageTitle).append("'");
sql.append(",").append("'").append(printStyle).append("'");
sql.append(",").append("'P'");
sql.append(",").append("' '");
sql.append(",").append("CURRENT DATE");
sql.append(",").append("CURRENT TIME");
sql.append(",").append("'").append(lastUpdateId).append("'");
sql.append(",").append("CURRENT DATE");
sql.append(",").append("CURRENT TIME");
sql.append(",").append("'").append(longMessage).append("'");
sql.append(")");
System.out.println("Display SQL Statement: " + sql);
connection = DriverManager.getConnection(DATABASE_URI, USER, PASS);
ps = connection.prepareStatement(sql.toString());
ps.executeUpdate();
System.out.println("Refreshed Record: ");
catch (SQLException sqle) {
System.out.println("SQLException: "+ sqle + ". SQLSTATE=" + sqle.getSQLState()+" SQLCODE=" + sqle.getErrorCode());
finally {
if (ps != null) {
try {
ps.close();
ps=null;
catch (Exception e) {}
if (ps1 != null) {
try {
ps1.close();
ps1=null;
catch (Exception e) {}
if (connection != null) {
try {
connection.close();
connection = null;
catch (Exception e) {}
if (connection1 != null) {
try {
connection1.close();
connection1 = null;
catch (Exception e) {}
return list;
if my longMessage is smaller like one line then everything works fine, but as soon as my longMessage if greater than 254 it starts giving me -404. How do I work around or Is there any way to use host variable in Java?
All kind of help is appreciated. Any question then please email me at [email protected].
Thank you.

This is what you got to do to insert a larger value.
//Assuming that message length is less than 254+ 254 characters.
//If larger then run the update loop that many times.
String longMessage = "Blah blah ... ";
String firstPart = "";
String secondPart = "";
int messageLength = longMessage.length();
if (messageLength > 254)
     try
          firstPart = longMessage.subString(0, 253);
          secondPart = longMessage.subString(254, message);
     catch (IndexOutOfBoundsException e)
//In the first insert  set the first 254 characters
ps.setString(1, firstPart);
int result = ps.executeUpdate();
if (result != 0)
       System.out.println("Insert  sucessful  ");
       if (messageLength > 254)
            //now update with the second part.
            static String UPDATE_SECOND_PART = UPDATE my.table SET LONG_COL = LONG_COL || ? WHERE KEY_COL = ?;
            ps2 = connection.getPreparedStatement(UPDATE_SECOND_PART);
            ps2.setString(1, secondPart);
            ps2.setString(2, businessId);  //assuming that businessId is the primary key.
            int result2 = ps2.executeUpdate();
            if (result2 != 0)
                  System.out.println("Update  sucessful  ");
            else
                 System.out.println("Update failed ");
else
       System.out.println("Insert failed ");
}Hope this helps.

Similar Messages

  • How to use odi variable in java code.

    Hi,
    I am trying to calculate check sum of a file and need to capture that in a odi variable...
    I wrote code like this(selected technology as java bean shell)
    <@
    import java.io.*;
    import java.util.zip.*;
    public class checksum {
    public static void main(String[] args) throws Exception {
    FileInputStream fis = new FileInputStream(new File("c:/dummy.txt"));
    CheckedInputStream cis = new CheckedInputStream(fis, new CRC32());
    BufferedInputStream in = new BufferedInputStream(cis);
    while (in.read() != -1) {
    #checksum = cis.getChecksum().getValue();
    }@>
    But I am not able to get that value...
    I tried in another way like this
    <@
    import java.io.*;
    import java.util.zip.*;
    public class checksum {
    public static void main(String[] args) throws Exception {
         long result;
    FileInputStream fis = new FileInputStream(new File("c:/dummy.txt"));
    CheckedInputStream cis = new CheckedInputStream(fis, new CRC32());
    BufferedInputStream in = new BufferedInputStream(cis);
    while (in.read() != -1) {
    result= cis.getChecksum().getValue();
    @>
    In odi variable refreshing mode i selected schema as memory_engine and wrote
    select '<@=result@>' from dual;
    even this wont work for me :(
    Anyone pls help me in this...
    Thanks in advance
    Pavan

    Hi Phani,
    Thanks for the reply. I resolved this. The mistake is I wrote java code in a class,in main function. I removed class and main function. Now I am able to capture value into Odi variable...
    I modified code as
    <@
    import java.io.*;
    import java.util.zip.*;
         long result;
    FileInputStream fis = new FileInputStream(new File("C:/dummy.txt"));
    CheckedInputStream cis = new CheckedInputStream(fis, new CRC32());
    BufferedInputStream in = new BufferedInputStream(cis);
    while (in.read() != -1) {
    result=cis.getChecksum().getValue();
    @>
    finally retrieving result value from dual
    select '<@=result@> from dual
    Edited by: 908443 on Jan 16, 2012 10:42 PM

  • How to use the variables used in the message mapping

    Hi ,
    In the message mapping we can declare variables in the JAVA section , these variables could be used across the mapping .
    I have tried using it but I am unable to retrieve the values assigned to the variables in one UDF into the another UDF .
    Please guide me how to use the variables declared in the JAVA section in the message mapping .
    Thanks
    Anita Yadav

    Anita,
    I have worked on the Global variables and i found no issues. Make sure that the variable is declared in the Declaration Section and then initlaized in the Initialization section.
    If you declare a variable in the Declaration Section ,
    int i;
    then in any udf you can use if directly. No need to re declare  the variable in the UDF. If you do this, then it becomes a local variable.
    Regards,
    Bhavesh

  • How to use a variable on columns using Oracle Data Integrator

    How to use a variable in oracle Data Integrator expically on colums.

    yes exactly,i selected update on new column,if i didn't select update on new colum then error is not coming regarding update.
    but this time error is coming on "insert new rows".
    java.lang.NullPointerException
         at com.sunopsis.dwg.dbobj.SnpSessTaskSql.bindSessVar(SnpSessTaskSql.java)
         at com.sunopsis.dwg.dbobj.SnpSessTaskSql.bindSessVar(SnpSessTaskSql.java)
         at com.sunopsis.dwg.dbobj.SnpSessTaskSql.treatTaskPreTrt(SnpSessTaskSql.java)
         at com.sunopsis.dwg.dbobj.SnpSessTaskSql.treatTask(SnpSessTaskSql.java)
         at com.sunopsis.dwg.dbobj.SnpSessStep.treatSessStep(SnpSessStep.java)
         at com.sunopsis.dwg.dbobj.SnpSession.treatSession(SnpSession.java)
         at com.sunopsis.dwg.cmd.DwgCommandSession.treatCommand(DwgCommandSession.java)
         at com.sunopsis.dwg.cmd.DwgCommandBase.execute(DwgCommandBase.java)
         at com.sunopsis.dwg.cmd.e.i(e.java)
         at com.sunopsis.dwg.cmd.g.y(g.java)
         at com.sunopsis.dwg.cmd.e.run(e.java)
         at java.lang.Thread.run(Unknown Source).
    Can u please tell me what stpes i have to follow to solve this

  • How to use shared variables?

    Hello..
            Can anybody please guide me in using shared variables... I'm learning LabVIEW 8.5.... But did not understand how to use shared variables... I tried to read web pages regarding shared variables but got confused.... So anyone can please help me...?
             Thanks for any help from you...

    You will have to give us the whole picture. What is your client computer; a PAC, desktop etc? What are you running on the client computer; a VI or an executable? Where are you going to deploy your library? On the host machine or the client machine?
    If I assume that you are running a VI on the client machine and are depolying the library on the host, all you have to do is to create another shared variable and bind it to the variable on the host machine. You can do this by checking the Bind to Source option when creating the variable and browsing to the network item in options. Be sure to have the library deployed on the host side before you attempt to do this otherwise you won't be able to find the variable.
    Adnan Zafar
    Certified LabVIEW Architect
    Coleman Technologies

  • How to use Environment variables in Context Settings

    I need to set some Preferences using a Context, and in the value of the preference I need to use a path which may change depending on the OS.
    I need to use environment variables or java variables to create the relative path for the value.
    Is possible to access env variables from a Context Setting?
    Just to give an example, I'm trying to set the M2_REPO variable in the classpath settings in the preferences menu.
    to user.home + /.m2/repository
    How can I access the user.home from there?

    Hi Matias,
    Sure, you can use substitute-variables command for this purpose.
    See the example below:
    concat [substitute-variables "${system_property:user.home}" | str] "/.m2/repository"]
    Kind regards,
    Ulyana.

  • How  can use a variable in the folowing code?

    How  can use a variable 'W_ROWNUM2' in the folowing code?
    MOVE '1' TO CNT.
    LOOP AT L_T_PM2.
                  CONCATENATE '0' CNT INTO W_ROWNUM2.CONDENSE W_ROWNUM2.
                   CONCATENATE 'F110V-VARI'W_ROWNUM2'(01)' INTO FLD2.
        perform  DYNPRO_FIELD       using FLD2
                                     L_T_PM2-vari12_con.
                   CNT = CNT + 1.
                   CONDENSE CNT.                                                              
    ENDLOOP.
    I need to increment the value of W_ROWNUM2.
    Please ,it is urgent!!

    Hello
    CONCATENATE 'F110V-VARI'W_ROWNUM2'(01)' INTO FLD2.
    Try using spaces between parts of the resulting string.
    CONCATENATE 'F110V-VARI'  W_ROWNUM2  '(01)'   INTO FLD2
    Regards
    Greg Kern.

  • How to use sql query in java ?

    i don't know how to use sql query in java code.
    who can give me some advice?
    thanks

    http://java.sun.com/developer/onlineTraining/Database/JDBC20Intro/

  • How to use bind variables in the following query

    CREATE OR REPLACE PROCEDURE MMDB.test IS
    sel_qtn VARCHAR2 (10);
    CURSOR PT_QUANTITY IS select * from mmdb.product_tree WHERE QUANTITY_CHECK ='E'
    AND run_id = 100
    a PT_QUANTITY%ROWTYPE;
    BEGIN
    FOR i IN PT_QUANTITY
    loop
    sel_qtn := i.quanttity-1;
    While sel_qtn>=1
    loop
    insert into mmdb.product_tree (BILLING_ACCOUNT_NO ,S_CODE) values (i.BILLING_ACCOUNT_NO ,i.S_CODE||'E');
    sel_qtn :=sel_qtn -1;
    End loop;
    commit;
    end;

    Don't duplicate threads: How to use bind variables in the following query

  • How to use bind variables in this procedure

    Hi Experts,
    How to use bind variables in this procedure for static queries.
    PROCEDURE DELETE_MER_PROC (M_id IN NUMBER)
    IS
    BEGIN
    V_date DATE;
    SELECT PD_DATE INTO v_date FROM PD_MAINTAIN;
        DELETE FROM MER_CLEAR
        WHERE MER_DT < v_date
        AND ID = M_ID;
    COMMIT;
    END;   
    How to use  v_date and m_id as bind variables in this procedure to avoid hard parsing.
    Please help me.
    Thanks.

    976208 wrote:
    How to use  v_date and m_id as bind variables in this procedure to avoid hard parsing.
    You cannot avoid hard parsing - as the 1st time a SQL statement (like the SELECT or DELETE statements in your code) is encountered, it does not reside in the server's Shared Pool, and needs to be added into the pool via a hard parse.
    Bind variables does not prevent hard parsing. Hard parsing happens when the SQL statement (with or without bind variables) is a brand new statement encountered by the server.
    Bind variables enables the same SQL cursor to be reused, by simply changing the bind variable value.
    Not using bind variables means that each SQL statement is unique and not shareable - as the value is hardcoded into the statement and cannot be changed via a bind value. This typically means LOTS of different SQL statements (where the only difference is the changed value in the statement) are created - with each statement being a new statement not seen before in the Shared Pool and needing to be hard parsed.
    One does not design one's code not to be hard parsed. There ALWAYS will be a hard parse in order to get a SQL statement into the Shared Pool. One designs one's code to REUSE cursors in the Shared Pool.

  • How to use Bind Variables in Essbase data control

    Hi,
    I am trying to use Bind Variables in MDX query while creating the Essbase Data Control. I have used the below query with the Bind Variable.. this query is working in Essbase admin console..but it is throwing error (*Invalid MDX Query)* while creating Essbase Datacontrol in JDeveloper.
    MDX Query : SELECT {[Measures].Msr_2} ON COLUMNS, [Time].Children ON ROWS FROM cube
    where ($name)
    Could any body suggest me on how to use bind variables with Essbase Data control.
    Thanks,
    Swathi

    Hello Swathi, can you please help me how you created Essbase DataControl? Also were you able to figure out this?
    Thanks, Praveen.

  • How to use bind variable

    Hi,
    I have the below cursor 1 which is working already.For my requirement i want to use bind variable like second cursor.But its telling Bind Variable "p_col_list" is NOT DECLARED.Please any onehelp me on this.
    How to use bind variable Here.
    Cursor1:
    DECLARE
    emp_cv sys_refcursor;
    iid NUMBER := 1;
    i_sql varchar2(100);
    p_col_list varchar2(2000) := 'aaa,bbb,ccc,ddd';
    BEGIN
    i_sql := 'select '''||REPLACE(p_col_list, ',', ''',''')||''' from dual '||CHR(10) ;
    dbms_output.put_line(i_sql);
    OPEN emp_cv FOR i_sql ;
    END;
    Cursor2:
    DECLARE
    emp_cv sys_refcursor;
    iid NUMBER := 1;
    i_sql varchar2(100);
    p_col_list varchar2(2000) := 'aaa,bbb,ccc,ddd';
    BEGIN
    i_sql := 'select '''||REPLACE(:p_col_list, ',', ''',''')||''' from dual '||CHR(10) ;
    dbms_output.put_line(i_sql);
    OPEN emp_cv FOR i_sql using p_col_list;
    END;

    hello,
    the reports parameterform capabilities are limited. if you want
    to create sophisticated parameterforms, you should do that with
    oracle forms or html forms.
    regards,
    the oracle reports team --pw                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • How to use ADF variables in C:when test?

    I have a <af:iterator in my page fragment as follows
    <af:iterator id="i1" value="#{queryModel.currentDescriptor.conjunctionCriterion.criterionList}" var="criterion" varStatus="vs">
    Within this iterator, I want to make a decision absed on the index of the iterator. To do this test, I am using jstl as follows
    <c:when test="${vs.index == '0' or vs.index == '2' or vs.index == '4'}">
    This test is however always evaluating to false. I have tried cahnging my code using various combiantion as below ...
    <c:when test="#{vs.index == '0' or vs.index == '2' or vs.index == '4'}">
    <c:when test="${vs.index == 0 or vs.index == 2 or vs.index == 4}">
    <c:when test="${vs.index == '0' || vs.index == '2' || vs.index == '4'}">
    But nothign seems to be working fine.
    Can some one help me with what I am doing wrong?
    Thanks.

    How to use ADF variables in <C:when test?

  • How to use C-Structure in java applets

    hi alls,
    I want to use a struct model (struct in C++) in java applets. i know class is used in java applications. but, how can i convert in java applets?
    class renk
    int r;
    int gr;
    int b;
    import java.awt.Graphics;
    import java.awt.Color;
    import java.awt.Event;
    import java.applet.Applet;
    public class benek extends Applet
    final int n=10;
    int x[] = new int[n];
    int y[] = new int[n];
    int count = 0;
    renk clr[] = new renk[n];
    public void init()
    setBackground(Color.black);
    public boolean mouseDown(Event yordam, int xyer, int yyer)
    if (count<n)
    System.out.println("...");
    ekle(xyer,yyer);
    else System.out.println("Kapasite Doldu...");
    return true;
    void ekle(int xyer, int yyer)
    int r1 = (int)Math.floor(Math.random()*256);
    int gr1 = (int)Math.floor(Math.random()*256);
    int b1 = (int)Math.floor(Math.random()*256);
    clr[count].r = r1;
    clr[count].gr = gr1;
    clr[count].b = b1;
    x[count]=xyer;
    y[count]=yyer;
    count++;
    repaint();
    public void paint(Graphics g)
    it gives error message... how can � use struct model in java applets???
    if you help me i will be greatfull....

    � use import but it doesn't work.
    i add: import renk; or import class renk;
    how will � add import I assumed based on your initial post that the renk and benek classes were in the same file. Apparently you're saying they are not. So for another thing, make your renk class "public class renk", and add the "public" keyword to the 3 members of that class. Then if your code still doesn't see the "renk" class, it would just be that you don't have the directory that contains the compiled "renk.class" in your classpath.

  • How to use " toFront() " method in java application and in which package or

    How to use " toFront() " method in java application and in which package or class having this toFront() method.if anybody know pl. send example.

    The API documentation has a link at the top of every page that says "Index". If you follow that and look for toFront(), you will find it exists in java.awt.Window and javax.swing.JInternalFrame.
    To use it in a Java application, create an object x of either of those two classes and write "x.toFront();".

Maybe you are looking for

  • Just tried to wipe old nano clean and resync w/new playlists, but getting "

    ....cannot be synced b/c all of the playlists selected for syncing no longer exist" i am staring at thtem all in our library right now, how could this be?

  • Iphone 3gs will not sync with itunes copied from external hard drive.

    We transferred itunes from an external hard drive to a new laptop pc, after copying it from our old desktop.  I connected a new iphone 3gs on the laptop (first iphone on any of our computers), and itunes does not recognize the iphone, so it does not

  • Cannot Access Routers Web Based Page?

    I have a wireless Linksys router Model WRT54G and it will not let me access my routers web based page. When I enter the default IP address into the Address Bar nothing happens (I've checked to make sure my router is on the default IP), i just get a b

  • About converting byte to send SMS in Javacard

    Hello all, I'm try to send a location information out by put it in the unformat SMS. The location will return in 7 bytes; which including MCC and MNC (3 bytes), LAC (2 bytes), and cell id (2 bytes). Suppose it is 02 F8 00 | 00 14 | 00 79, it means MC

  • Search Help Exfit for Material

    Hi, Scenario: in the F4 dropdown for material, I have added a new elementary search help which will search a laterial based on material description(makt-maktx)/basic material(mara-wrkst)/size & dimension(mara-groes). Requirement: I need to add one mo