Note that there are some explanatory texts on larger screens.

plurals
  1. POResultset handling error in servlet code
    text
    copied!<p>I write a code in servlet for login checking I don't know why I get an error like <code>java.sql.SQLException: No data found</code>, if I had not commented out the <code>String s4 = rs.getString(1)</code> and <code>out.println(s4)</code> line if I commented out this lines I did not get any error.</p> <p>Why do I get an error like this? I cannot find out the answer.</p> <pre><code>import java.io.IOException; import java.io.PrintWriter; import javax.servlet.*; import javax.servlet.http.*; import java.sql.*; public class login extends HttpServlet { Connection conn; Statement stmt; ResultSet rs; String s = ""; public void init() { try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); conn = DriverManager.getConnection("Jdbc:Odbc:edsn"); s = "Your information is connected ......"; } catch (Exception e) { s = "Exception 1....." + e.getMessage(); } } public void doPost(HttpServletRequest req, HttpServletResponse res) throws IOException, ServletException { res.setContentType("text/html;charset=UTF-8"); PrintWriter out = res.getWriter(); out.println(s); try { String ID = req.getParameter("T1"); String query = "select * from user_db "; stmt = conn.createStatement(); rs = stmt.executeQuery(query); out.println("user" + " " + "pass"); while (rs.next()) { try { if ((rs.getString(1)).equals(ID)) { String s4 = rs.getString(1); out.println(s4); out.println("&lt;html&gt;&lt;body&gt;&lt;h&gt; login Pass.....:(&lt;/h&gt;&lt;/body&gt;&lt;/html&gt;"); } } catch (Exception e) { out.println(e); } } } catch (Exception e) { out.println("Unable To Show the info... . . ." + e.getMessage()); } } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload