JAVA MySql multiple word search

Posted by user1703849 on Stack Overflow See other posts from Stack Overflow or by user1703849
Published on 2012-11-18T22:58:12Z Indexed on 2012/11/18 22:59 UTC
Read the original article Hit count: 235

Filed under:
|
|

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());
    }
}
} 

© Stack Overflow or respective owner

Related posts about java

Related posts about mysql