mysql - java.sql.SQLException: Before start of result set -
i'm facing problem getting data mysql
database. code following:
try { connection con = datasource.getconnection(); statement stmt = con.createstatement(); resultset rs; rs = stmt.executequery("select tittle,date,path " + "from announcement "+ "order date"); string tittle=rs.getstring("tittle"); string date=rs.getstring("date"); string text=rs.getstring("path"); if (!rs.isbeforefirst()) { out.println("<p>no data !</p>"); } else { out.println("<table class=\"data\">"); out.println("<tr ><td class=\"sectionheader\"> tittleĻ</td><td class=\"sectionheader\">date</td><td class=\"sectionheader\">text</td></tr>"); while (rs.next()) { string row=""; row += "<td><a href=\"\"> "+tittle+ "</td>"; row += "<td>" + date + "</td>"; row +="<td>"+text+"</td>"; row +="</tr>"; out.println(row); }
the error "java.sql.sqlexception: before start of result set"
tip of doing wrong?
thank in advance.
you access data in resultset object through cursor. cursor points before first row.
while(rs.next()) { string tittle=rs.getstring("tittle"); .... }
more it, query might return more 1 row, in case, may want store results in collection, list<map<string, string>>
, each entry in list represents 1 row query resutls , map hold column name vs column value.
Comments
Post a Comment