I want to hyphenate a token which is present in a database. My code:

String str = "The Appointments Committee Cabinet has approved the appointment of Dr. Harry Potter, Chief Economic Adviser, Department of Economic Affairs as Executive Director in the International Monetary Fund.";
String[] words = str.split(" ");
LinkedList<String> linkedlist=new LinkedList<String>();
for (int i = 0; i <= words.length-1; i++) {
ListIterator itr = linkedlist.listIterator();
Connection con = null;
PreparedStatement pstTemp = null;
StringBuilder tokens = new StringBuilder();
try {
con = DBConnection.getJndiConnection();
StringBuffer sbQry = new StringBuffer("SELECT englishlex FROM lex_hindi where (domain='Tourism' or domain='Zgeneral') and englishlex=");

while (itr.hasNext()) {

sbQry.append("'"+tokens+ "',");


sbQry.append(" order by length(englishlex) desc");

} catch (SQLException ex) {
Logger.getLogger(PhraseMarker.class.getName()).log (Level.SEVERE, null, ex);
I want to implement this algorithm, I will start with "The Appointments", whether it is present in table or not. If yes, then move forward and check for the next token- whether entry for "The Appointments Committee" is present. If yes, then again move forward, and check for "The Appointments Committee Cabinet". If entry is present, then again move forward, if not, then move back, then hyphenate "The-Appointments-Committee". Then again start with "Cabinet"- the same process all over again. I want to use a select query- it should give a smaller result set, so the speed should be much faster.please suggest changes in my code