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

  • SEARCH
  • Home
  • 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 6909353
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T08:40:43+00:00 2026-05-27T08:40:43+00:00

I have a mysql table named ‘customer’. serialnumber (int), name(varchar), gender(varchar) are the table

  • 0

I have a mysql table named ‘customer’. serialnumber (int), name(varchar), gender(varchar) are the table fields.

I have a int variable a = 2.

I want to fetch the value from the table when serialnumber = a. That is when the serialnumber = 2 it should display the particular customer’s name.

String url="jdbc:mysql://localhost/shopping";
String usr ="root";
String pass = "rootpassword";

session.setAttribute( "URL", url );
session.setAttribute( "user", usr );
session.setAttribute( "passwd", pass );

String connectionURL = (String)session.getAttribute( "URL" );
String user = (String)session.getAttribute("user");
String passwd = (String)session.getAttribute("passwd");
Connection connection = null;
Statement statement = null;
ResultSet rs = null;
try {
      Class.forName("com.mysql.jdbc.Driver").newInstance();
      connection = DriverManager.getConnection(connectionURL, user, passwd);
      statement = connection.createStatement();

rs=statement.executeQuery("select * from customer where serialnumber like '%a%' ");

      while (rs.next()) {
      out.println("Customer Name: ");
      out.println(rs.getString("name")); 
     }rs.close();
    }catch(Exception ce){out.println(ce);}             

This throws me nothing. But when i give the number instead a in rs.execute Query it displays the customer name. How to solve this and what is my mistake??

Thanks

  • 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-27T08:40:44+00:00Added an answer on May 27, 2026 at 8:40 am

    You are treating a like a literal, instead of a variable. You will need to update the query like this:

    executeQuery("SELECT * FROM customer WHERE serialnumber LIKE '%" + a + "%' ");
    

    I did not include rs = statement. for brevity, and to remove the scrolling. You will still need it for your solution.


    @ypercube makes a good point: If you are looking to see when the serialnumber is exactly 2:

    rs = statement.executeQuery("SELECT * FROM customer WHERE serialnumber = " + a);
    

    Also, if you’re only using the name field, you shouldn’t SELECT * but instead SELECT name

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

Sidebar

Related Questions

Say i have a table named tbl1 in mysql :- bookid int name varchar(20)
I have a mysql table structure like that: id int primary key name varchar
Suppose i have a mysql table name table with fields rank date id The
I have the following MySQL table named proposals: proposal_id proposal_user (int proposal_book (int) proposal_date
In mysql database I have a table named bug_list tables name: bug_list id projectId
I have a mysql table named events. Some events are featured. I want to
I have a mysql table named users having fields: username, password, email I have
I have a mySQL table named events with 4 fields (event_id, event_name, event_start_date, event_end_date)
I have a MySQL table named contentcontaining (a.o.) the fields _date and text, for
I have a mysql table named dev with a column of emails. I want

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.