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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T23:44:29+00:00 2026-06-11T23:44:29+00:00

I wanted to search some keywords from particular column and print all the column

  • 0

I wanted to search some keywords from particular column and print all the column values corresponding to the keyword, Now the problem is if I use query

Select * from Candidate where skills like %C% , and different rows in skills are:

Java, C, C++, HTML, CSS, Net Beans, My Eclipse

Java, Asp.Net, Eclipse

C, PHP, CSS, Hibernate

Now it is diplaying all the rows as C is a substring in every row, I tried to use C% rather than %C% but only 3rd line is displayed as it starts with C but I need to show all the Rowrs having “C” as a different word, How can I search the full world, Suggest piece of code.

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

public class TokensOfString 
{
    public static void main(String[] args) 
    {
        String str;
        String query = "";
        try
        {
            int i =0, cntToken =0;
            BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
            System.out.println("Enter the keywords to be searched");
            str = br.readLine();
            StringTokenizer words = new StringTokenizer(str, ",");
            cntToken = words.countTokens();
            //System.out.println("No. of Tokens = "+cntToken);

            String token[]= new String[cntToken];

            while(words.hasMoreElements())
            {
                token[i] = words.nextToken().trim();
                //System.out.println(token[i]);
                i++;
            }
                //System.out.println(++i+" : "+words.nextElement().toString().trim());    

            query = "SELECT * from can_skills where skills  like '"+ token[0] +"%'";
           // System.out.println("Query at 34 : "+query);
            if(cntToken == 1)
            {
                query ="";
                query = "SELECT * from can_skills where skills  like '"+ str +"%'";
            }
            if(cntToken > 1)
            {
                for( int j=1; j < cntToken; j++)
                query = query + " or skills  like '"+ token[j] +"%'";
            }
            System.out.println("Query at 43 : "+query);

            Connection con = null;
            Class.forName("com.mysql.jdbc.Driver");
            String hostName = "localhost";
            String port = "3306";
            String userName = "root";
            String password = "root";
            con = DriverManager.getConnection("jdbc:mysql://" + hostName + ":" + port + "/prem", userName, password);
            Statement statement= con.createStatement();
            ResultSet rs = statement.executeQuery(query);
            while(rs.next())
            {
                System.out.println(rs.getString(4));
            }

        }
        catch(ClassNotFoundException e){ System.out.println(e); }
        catch(Exception ex){ System.out.println(ex); }
    }
}
  • 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-11T23:44:30+00:00Added an answer on June 11, 2026 at 11:44 pm

    Use a regular expression in instead of a like expression:

    select *
    from Candidate
    where skills regexp '^C,| C,| C$'
    

    The | means or. The ^ means the beginning of the string and the $ means the end. So it will match the token in the beginning, the end and in the middle of the string. Notice that there are spaces before the second and third cases.

    In java, if I didn’t get it wrong:

    "SELECT * from can_skills where skills regexp '^" + token[0] + ",| " + token[0] + ",| " + token[0] + "$'";
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I wanted to use jFlex. Tried to search online tutorials. But all points to
I have tried to use mysql fulltext search in my intranet. I wanted to
Wanted some help with a problem with mapkit I am facing. Should be a
Recently I wanted to implement a printf wrapper. After some search I found the
I am sitting playing with elastic search from C#, and I wanted to create
I wanted some tool which could check all the standard violations that I make
Hello I am working in django how to use a search form from Django
I've recently been working on some database search functionality and wanted to get some
I wanted to implement a search feature for my web app. I choose Haystack
I'm creating video music search in android WebView and I wanted users can launch

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.