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 8852225
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T13:20:46+00:00 2026-06-14T13:20:46+00:00

i have a database in MySql that has a name column in it which

  • 0

i have a database in MySql that has a name column in it which contains several words(description). I am connected to database with java through eclipse. I have a search, that returns results if only name field contains one word.
id:………………name:…………..info:………………….type:>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
1……………….balloon……….big red balloon…………….big>>>>>>>>>>>>>>>>>>>
2………………..house……….expensive beautiful…………luxury>>>>>>>>>>>>>>>>>>>>>>>>>
3…………….chicken wings…….deep fried wings……………tasty

these are just random words but as an example my search can only see ex. balloon and then show info,
but if i type chicken wings, it does nothing. so it possible somehow to search from columns with multiple words?
this is my search code below

import java.io.*;
import java.sql.*;
import java.util.*;

class Search {

public static void main(String[] args) {
    Scanner inp``ut = new Scanner(System.in);

    try {
        Connection con = DriverManager.getConnection(
                "jdbc:mysql://example/mydb", "user", "password");
        Statement stmt = (Statement) con.createStatement();

        System.out.print("enter search: ");
        String name = input.next();

            String SQL = "SELECT * FROM menu where name LIKE '" + name + "'";

        ResultSet rs = stmt.executeQuery(SQL);

        while (rs.next()) {
            System.out.println("Name: " +rs.getString("name"));
            System.out.println("Description:  " + rs.getString("info") );
            System.out.println("Price: " + rs.getString("Price"));

        }

    } catch (Exception e) {
        System.out.println("ERROR: " + 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-06-14T13:20:47+00:00Added an answer on June 14, 2026 at 1:20 pm

    The way you are performing the search now, you are at first vulnerable to sql injection and might want to use the PreparedStatement of JDBC instead of the normal statement.

    Second, I would recommend splitting the user input at the space and searching for all the terms alone with “OR”.

    Example: User inputs house expensive beautiful

    Search would be:

    SELECT * FROM menu where name LIKE '%house%' OR name LIKE '%expensive%' OR name LIKE '%beaufitful%'
    

    I have put percentage signs because if you would search for ‘house’, only the exact term “house” will be matched. By searching with “%house%”, the strings “somethingbeforehouse” and “houseandsomethingafter” will be also found.

    Hope this helps you!

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

Sidebar

Related Questions

I have a mysql database that has text stored in it with non encoded
I have a website that has approx 1000 different strings in a mysql database
I have a MySQL database that I am keeping temperature readings from several different
The code below works great. I have a MySQL database that contains book titles
I have several columns in a MySQL database that I would like to add
I have a table in MySQL which name is clienttable and it has 11
this is my problem: I have a table in my mysql database which contains
I have a mysql database that is tracking hockey stats. What I'd like to
I have a MySql database that stores a timestamp for each record I insert.
I have a mysql database that looks like this: |id | city | created

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.