0

In database mapRule column contains

  1. IFA 211974009 | Deep partial thickness burn of toe(s) (disorder) |
  2. IFA 28571002 | Second degree burn of toe (disorder) |
  3. IFA 211968009 | Superficial partial thickness burn of foot (disorder) |

required output are in between | symbol pie or vertical bar

  1. Deep partial thickness burn of toe(s) (disorder)
  2. Second degree burn of toe (disorder)
  3. Superficial partial thickness burn of foot (disorder)

how to get this ? i am fetching data from mysql my code is

CODE

<%
    pstm = Con.prepareStatement(selectsql);
    pstm.setString(1, snomedid);
    resultSet = pstm.executeQuery();
    while (resultSet.next()) { %>
        <p><%=resultSet.getString("mapRule")%></p>
    <% } %>

how to validate in this case .?

1 Answers1

1

Use String.split, for example. It uses a regular expression as a divider to split your string into array of smaller chunks.

<%
pstm = Con.prepareStatement(selectsql);
pstm.setString(1, snomedid);
resultSet = pstm.executeQuery();
while (resultSet.next()) { 
  String[] chunks = resultSet.getString("mapRule").split("\\|");
  if(chunks.length > 1) { //Don't forget to check that string after first "|" even exists!
%>
        <p><%=chunks[1]%></p>
    <% }
} %>

Also, it might be a good idea to check if resultSet.getString("mapRule") == null if that's possible in your input data.

P.S. It's called a pipe character, not pie.

Timekiller
  • 2,946
  • 2
  • 16
  • 16
  • very thanks and its working fine ,i think now it won't need , i ll correct it next time sry for the mistake @Timekiller – new learner Dec 21 '15 at 17:25
  • how to avoid duplicates row in this case . am getting duplicates rows – new learner Dec 21 '15 at 17:56
  • Change your sql query, use `distinct` for starters. If there are still duplicates it might be necessary to cut the string between `|` directly in SQL - it's possible using regular expressions or `instr` and `substr`. You didn't mention what DBMS you use though, so it's hard to say what would be better to use. Look up how to split a string using delimiter in SQL, there are plenty of relevant answers on StackOverflow. – Timekiller Dec 21 '15 at 18:09
  • am using mysql . and i cant distinct directly because in my case am using only one select query where id ,in that am fetching data one by one based on selecting . so now i confused – new learner Dec 21 '15 at 18:15
  • Umm, what do you mean you can't use distinct? `select distinct mapRule from ....`. if that fails, use `select distinct substring_index(substring_index(mapRule, '|', 2), '|', -1) from ...` - this will cut out value between `|` directly in mysql and filter out duplicates. You won't need `split` in Java if you go with the latter. – Timekiller Dec 21 '15 at 18:21
  • i understand but in my program i cant change query ,thats the problem say ur mail id i ll send my code . – new learner Dec 21 '15 at 18:35
  • Sorry, no. I have enough to code on my own, I can only give some advice. Try to collect all of the resulting strings into a string array, then filter out duplicates. See http://stackoverflow.com/questions/10366856/delete-duplicate-strings-in-string-array for example. – Timekiller Dec 21 '15 at 18:39
  • ohh okay sry . ! ill check and i thought if u saw my code u can give some idea thats it, any how thanks for helping – new learner Dec 21 '15 at 18:45