Page 2 of 2 FirstFirst 12
Results 21 to 27 of 27
  1. #21
    DonCash's Avatar
    DonCash is offline Moderator
    Join Date
    Aug 2007
    Location
    London, UK
    Posts
    240
    Rep Power
    8

    Default

    Ah nice one Chris. Yeah that explains it well.
    Did this post help you? Please me! :cool:

  2. #22
    Join Date
    Apr 2008
    Location
    Fort Wayne, Indiana
    Posts
    62
    Rep Power
    0

    Default

    Take a look at this,

    Java Code:
      public static void main(String[] args) {
    
        String statement = "update employee\nset wtKey = name||pno||id\nwhere id is not null";
        String concat = "";
        String[] temparray, temparray2, temparray3;
        temparray = statement.split("=.?");//splits off equals sign and space afterwards
        temparray2 = temparray[1].split("\\n");//splits off last line
        concat = temparray2[0];//grabs the concat part of it
        temparray3 = concat.split("\\|\\|");//splits up by ||
        concat = " CONCAT(" + temparray3[0] + "," + temparray3[1] + "," + temparray3[2] + ")";//puts concat together
        statement = temparray[0] + "=" + concat + "\n" + temparray2[1];//reassembles statement
        System.out.println(statement);//output statement
    
      }
    Output:
    update employee
    set wtKey = CONCAT(name,pno,id)
    where id is not null

  3. #23
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

  4. #24
    DonCash's Avatar
    DonCash is offline Moderator
    Join Date
    Aug 2007
    Location
    London, UK
    Posts
    240
    Rep Power
    8

    Default

    Its the desired SQL query output he was looking for.... Good work Chris.
    Did this post help you? Please me! :cool:

  5. #25
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    Ah, I got it.

    Users better to mentioned some tips if the thread goes for more than one page, isn't it Don.

  6. #26
    raghu408 is offline Member
    Join Date
    Apr 2008
    Posts
    4
    Rep Power
    0

    Default

    Chris that's so nice of you but my API here should be dynamic i.e not specific to one SQL like i mentioned above:update employee\nset wtKey = name||pno||id\nwhere id is not null

    but if you send a valid query like:
    SELECT region_name || ' ' || store_name FROM Geography
    WHERE store_name = 'Boston';

    Then it should return:

    region_name || ' ' || store_name

    basically it should return all that are connected with ||

  7. #27
    Join Date
    Apr 2008
    Location
    Fort Wayne, Indiana
    Posts
    62
    Rep Power
    0

    Default

    Try this out.

    Java Code:
      static String compute(String temp) {
        String concat;//holds final concat
        String[] temparray;//holds parts after split
        String first, second, third;//divides three parts into three strings
        temparray = temp.split("\\|\\|");// splits up by ||
        first = temparray[0].substring(temparray[0].lastIndexOf(' ', temparray[0].length() - 2) + 1);//takes off first part by removing everything past last space
        second = temparray[1];//second part goes into  string
        if (temparray[2].indexOf(' ', 1) < temparray[2].indexOf(10, 1) | temparray[2].indexOf(10, 1) == -1) {//takes last part by removing everything until first space or line feed
          third = temparray[2].substring(0, temparray[2].indexOf(' ', 1));//in case of space
        } else {
          third = temparray[2].substring(0, temparray[2].indexOf(10, 1));//in case of line feed
        }
        concat = first + "||" + second + "||" + third;//builds the concat info
        return concat;
      }

Page 2 of 2 FirstFirst 12

Similar Threads

  1. i need an example of JSR179 ((Location based Ser)implementation for CDC based device
    By talk_to_vivekmishra in forum CDC and Personal Profile
    Replies: 3
    Last Post: 12-30-2010, 10:07 AM
  2. Replies: 4
    Last Post: 02-22-2009, 04:31 PM
  3. how to Parse int to a string variable
    By raj reddy in forum Java Servlet
    Replies: 10
    Last Post: 01-09-2009, 07:41 PM
  4. how to Parse int to a string variable (pls hlp)
    By raj reddy in forum Threads and Synchronization
    Replies: 5
    Last Post: 06-10-2008, 06:32 AM
  5. Replies: 1
    Last Post: 07-23-2007, 11:59 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •