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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T13:22:52+00:00 2026-06-15T13:22:52+00:00

I`m building a decision support system in java. Below is a part of code,

  • 0

I`m building a decision support system in java. Below is a part of code, that scans the search word that is typed in by user, then compares it with database searchlog.searchcolumn values and if the word is not there creates a new entry. BUT in the if statement i want it to check for the entry, and if it IS already in searchlog.searchcolumn column, then I want it NOT to create a new duplicate entry, but to add +1 value to searchlog.counter column for the specific word.
for example if search word is “UMBRELLA” and there is already one entry for umbrella in database, i want it to add +1 to counter column in UMBRELLA row.

the purpose of this, is to store all searchwords and keep a track of the most popular ones.
Thank you for your time
String CheckSearch = “SELECTsearchcolumn FROMsearchlog”;

String InsertColumn = "INSERT INTO `mydb`.`searchlog` (`searchcolumn`) VALUES ('"+ InputScanner + "'); 
         //
if (InputScanner.equals(CheckSearch)) 
   System.out.println("value ealready exist, counter well be updated"); 
else
   stmt.executeUpdate(InsertColumn); 

EDIT
Thank you for advice of using PreparedStatement, but this is my first more or less serious challenge and for this time, let`s just ignore vulnerability of my code. 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-06-15T13:22:53+00:00Added an answer on June 15, 2026 at 1:22 pm

    What database are you using? If you are using MySQL, then you should look into INSERT ... ON DUPLICATE KEY UPDATE statement. (Other SQL databases have MERGE, which I’m less familiar with.) Here is the MySQL Documentation.

    You will need make your searchcolumn a UNIQUE or PRIMARY column, then something along the lines of:

    INSERT INTO searchlog (searchcolumn, count) VALUES ("my search query", 0) ON DUPLICATE KEY UPDATE count = count + 1;

    will accomplish what you want.

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

Sidebar

Related Questions

I'm building a decision tree system in Scala, but some of the entries in
I am building an app that requires the user to login to get access
Building an inventory system. I have lots of products and each product has three
building a site using PHP and MySQL that needs to store a lot of
Building a website that has English & Japanese speaking users, with the Japanese users
Building a search with some custom objects and three scopes: All , Active ,
Building an iPhone OS application that will allow users to anonymously post information to
I am building a simple decision tree with jQuery. I have it running ok,
I am building a customer-facing website that requires me to build 1) some analytics
Do anyone know any incremental implementation of decision tree classifier. Such that it could

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.