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 .?

2
  • That looks like a very badly designed database. Commented Dec 21, 2015 at 18:43
  • yes ! how to remove duplicates in this case @Mark Rotteveel Commented Dec 21, 2015 at 18:53

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

8 Comments

very thanks and its working fine ,i think now it won't need , i ll correct it next time sry for the mistake @Timekiller
how to avoid duplicates row in this case . am getting duplicates rows
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.
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
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.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.