java - What is reason for sql result set couldn't return result set? -
i'm trying return result set method. i'm sure sql query out put result set. because in "while(rs.next())" method print values. problem when i'm returning result set values , try calling "while(rs.next())" in calling method doesn't print value. reason that?
/* calling method */
public void corpusretrivedemo(){ arraylist<string> wordall= new arraylist<string>(); /* word list corpus retrive */ wordall=allwordslist(sentence1); resultset rsnew=corpussentenceretrive(wordall); try { while (rsnew.next()) { system.out.println("heloooo2..."); } } catch (sqlexception e) { // todo auto-generated catch block e.printstacktrace(); } /* uni gram calculate */ double d1=calculateprobunigram(wordall,rsnew); system.out.println(d1); }
/* database retrieve method */
public resultset corpussentenceretrive(list wordlist) { preparedstatement pstmtfgram = null; connection conn = null; resultset rs2 = null; stringbuilder sb = new stringbuilder(); try { conn = getconnection(); sb.append("select cor_sentence corpus "); for(int k=0;k<wordlist.size();k++){ sb.append( " cor_sentence '%" + wordlist.get(k) + "%' or "); } sb.append(" 1=0"); pstmtfgram = conn.preparestatement(sb.tostring()); rs2 = pstmtfgram.executequery(); while (rs2.next()) { system.out.println("heloo1..."); } } catch (exception e) { e.printstacktrace(); } return rs2; }
"heloo1" printing correctly. calling method "helooo2" doesn't print. reason that? there wrong return statement?
as in question appending string string builder.
one thing thing that. @ last final string become like.
select cor_sentence corpus cor_sentence '%" + wordlist.get(k) + "%' or cor_sentence '%" + wordlist.get(k) + "%' or
due sql query trowing exception.
another way saying helloo1 printing. please comment below line in code , test.
while (rs2.next()) { system.out.println("heloo1..."); }
Comments
Post a Comment