Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: Set error to string buffer

  1. #1
    Junior Member
    Join Date
    Sep 2021
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Set error to string buffer

    StringBuffer sb = new StringBuffer();
    ExecutorService executor = Executors.newFixedThreadPool (10);
    for (String p:pCall) { Runnable runner -> {
    fProc="{call "+p+")"; csProcCall = con.prepareCall (fProc); csProcCall.registerOut Parameter (1,OracleTypes.VARCHAR) ;
    csProcCall.executeQuery (); String errorMsg = (String) csProcCall.getObject(1);
    Common.log(errorMsg);
    if (!errorMsg.equals IgnoreCase ("SUCCESS")) { errorMessage=errorMessage+errorMsg;
    }
    System.out.println("parallel procedure execution" + p);
    executor.execute (runner) ;
    sb.append("Started the procedure" + p);
    }
    executor.shutdown();
    while (!executor.isTerminated()) {
    }

    Please help me out to convert the if statement block to string buffer to run the code successfully

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Set error to string buffer

    convert the if statement block to string buffer
    Not sure what that means. Are you asking about how to use the StringBuffer class?
    What do you want to use the StringBuffer class for? Can you explain that?


    Please edit your post and wrap your code with code tags:

    [code]
    **YOUR CODE GOES HERE**
    [/code]

    to get highlighting and preserve formatting.

    Be sure the code is properly indented to make it easier to read and understand.
    The posted code is very hard to read and understand.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Sep 2021
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Set error to string buffer

    At First it was for loop now i have converted the part of code to multi threading so it doesn't support simple if statement for error statement so i have to set the error to string buffer. Please help me with that


    String proc=DBCRConstants.getDbcr Proc();
    String fProc=null;
    String [] pCall-new String[7];
    String errorMessage=""; 
    pCall-proc.split(", ");
    StringBuffer sb = new StringBuffer();
    ExecutorService executor =
          Executors.newFixedThreadPool (10);
    for (String p:pCall) {
     Runnable runner -> {
    fProc="{call "+p+")"; 
    csProcCall = con.prepareCall (fProc); csProcCall.registerOut Parameter (1,OracleTypes.VARCHAR) ;
    csProcCall.executeQuery (); 
    String errorMsg = (String) csProcCall.getObject(1);
    Common.log(errorMsg);
    if (!errorMsg.equals IgnoreCase ("SUCCESS")) 
    { 
    errorMessage=errorMessage+errorMsg;
    }
    System.out.println("parallel procedure execution" + p);
    executor.execute (runner) ;
    sb.append("Started the procedure" + p);
    }
    executor.shutdown();
    while (!executor.isTerminated()) {
    }

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Set error to string buffer

    i have to set the error to string buffer.
    Where is the String with the error message's text that you want to add to the StringBuffer?
    Where is the StringBuffer? Why can't you use the StringBuffer class's append method to add the String to it?
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. stringbuilder and string buffer
    By kanupriya1 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: April 3rd, 2014, 03:34 AM
  2. Replies: 0
    Last Post: December 5th, 2013, 07:49 PM
  3. Reversing a String with no Buffer
    By C++kingKnowledge in forum What's Wrong With My Code?
    Replies: 20
    Last Post: March 11th, 2013, 12:54 AM
  4. Java String Buffer
    By anonb in forum Object Oriented Programming
    Replies: 3
    Last Post: December 19th, 2012, 02:59 AM
  5. [SOLVED] difference between String Concatenation and String -Buffer/Builder .append(<value>)
    By chronoz13 in forum Java Theory & Questions
    Replies: 5
    Last Post: September 3rd, 2011, 08:16 AM