|
|
Welcome to the Java Forums.
You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:
- have access to post topics
- communicate privately with other members (PM)
- not see advertisements between posts
- have the possibility to earn one of our surprises if you are an active member
- access many other special features that will be introduced later.
Registration is fast, simple and absolutely free so please, join our community today!
If you have any problems with the registration process or your account login, please contact us.
|
|

04-10-2008, 02:34 PM
|
 |
Moderator
|
|
Join Date: Aug 2007
Location: London, UK
Posts: 239
|
|
|
Ah nice one Chris. Yeah that explains it well.
__________________
Did this post help you? Please To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts. me! To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
|

04-10-2008, 03:07 PM
|
 |
Member
|
|
Join Date: Apr 2008
Location: State College, PA
Posts: 50
|
|
Take a look at this,
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
|
|

04-10-2008, 03:10 PM
|
 |
Moderator
|
|
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 3,578
|
|
|
What this mean pal.
__________________
Use an appropriate Subject. "Help, urgent!" isn't one. To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Has someone helped you? Then you can To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts. their helpful post.
Want to make your IDE the best? To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
|

04-10-2008, 03:17 PM
|
 |
Moderator
|
|
Join Date: Aug 2007
Location: London, UK
Posts: 239
|
|
|
Its the desired SQL query output he was looking for.... Good work Chris.
__________________
Did this post help you? Please To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts. me! To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
|

04-10-2008, 03:29 PM
|
 |
Moderator
|
|
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 3,578
|
|
|
Ah, I got it.
Users better to mentioned some tips if the thread goes for more than one page, isn't it Don.
__________________
Use an appropriate Subject. "Help, urgent!" isn't one. To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Has someone helped you? Then you can To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts. their helpful post.
Want to make your IDE the best? To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
|

04-10-2008, 09:51 PM
|
|
Member
|
|
Join Date: Apr 2008
Posts: 4
|
|
|
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 ||
|
|

04-10-2008, 11:55 PM
|
 |
Member
|
|
Join Date: Apr 2008
Location: State College, PA
Posts: 50
|
|
Try this out.
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;
}
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|