Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7517795
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T01:33:53+00:00 2026-05-30T01:33:53+00:00

I write a code in servlet for login checking I don’t know why I

  • 0

I write a code in servlet for login checking I don’t know why I get an error like java.sql.SQLException: No data found, if I had not commented out the String s4 = rs.getString(1) and out.println(s4) line if I commented out this lines I did not get any error.

Why do I get an error like this? I cannot find out the answer.

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("<html><body><h> login Pass.....:(</h></body></html>");

                    }

                } catch (Exception e) {
                    out.println(e);
                }
            }

        } catch (Exception e) {
            out.println("Unable To Show the info... . . ." + e.getMessage());
        }

    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T01:33:54+00:00Added an answer on May 30, 2026 at 1:33 am

    Why write the code like this ? It’s very wasteful going over the whole table…
    The IO alone…
    Why not change to this:

    ResultSet rs = null;
    PreparedStatement st = null;
    try {...
    String ID = req.getParameter("T1"); 
                String query = "select 1 from user_db where col_name = ?"; 
                st = conn.prepareStatement(query);
                st.setString(1, ID);  
                rs = st.executeQuery();
    if (rs.next()) {
      out.println(ID); 
      out.println("<html><body><h> login Pass.....:(</h></body></html>"); 
    }
    ..
    
    } finally {
    if (rs != null) try { rs.close();}catch (Exception e) {}
    if (st != null) try { st.close();}catch (Exception e) {}
    }
    

    notice prepared statements are cached and better for frequent use

    you let the db do what its good at – search the data

    select 1 instead of select * does not bring back data you dont really need

    jdbc works harder the more columns and data in general you return, so only get what you
    need

    and add a finally block to always close your db connections properly

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm writing HTML code for a Java servlet. I first write the code in
In order to write servlets code I need servlet-api.jar. Where do i get servlet-api.jar
I wrote some code to read a file in my Java Servlet class. (I'm
Many beginning programmers write code like this: sub copy_file ($$) { my $from =
When I write code like this in VS 2008: .h struct Patterns { string
if we write a code in jsp that will convert to servlet code and
I need to write a download servlet in java to download a file from
I am trying to write some test code for my java application using Scalatest.
Write code to determine if a number is divisible by 3. The input to
How do I write code where a company icon appears on the left side

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.