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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T19:32:13+00:00 2026-06-13T19:32:13+00:00

I am trying to do a SELECT using PreparedStatement , but not getting any

  • 0

I am trying to do a SELECT using PreparedStatement, but not getting any results back, despite the data being present. If I use Statement instead, I get the desired results, so not sure why I don’t get anything with the PreparedStatement.
Any ideas?

Here is my code:

String species = "Snail";
PreparedStatement preparedStatement = con.prepareStatement("Select * from lifeforms where species=?",PreparedStatement.RETURN_GENERATED_KEYS);
preparedStatement.setString(1, species);
preparedStatement.execute();
ResultSet resultSet = preparedStatement.getGeneratedKeys();

Also – I have tried just

resultSet = preparedStatement.execute();

But this won’t compile, saying I must change resultSet to expect a boolean value.

Any insights into this would be greatly appreciated.

Sorry if this is something obvious, but I have read the docs until I am almost unconscious, and I’m only just learning java.

  • 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-13T19:32:14+00:00Added an answer on June 13, 2026 at 7:32 pm

    Ah so I have finally found the answer to this question – in case anyone else is stuck on the same thing..

    The execute() method has no return value, although the compiler was suggesting it expected a boolean return value. Maybe it just returns true or false for successful or not?

    The executeUpdate() method returns an int value of the number of records updated/inserted or deleted.

    To get the result set of a query statement (e.g. Select * from someTable), use the
    ResultSet rs = preparedStatement.executeQuery() method.
    This will return the actual query results into a ResultSet variable.

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

Sidebar

Related Questions

Trying to read an RSS and select information using Linq but can't seem to
I'm trying to exclude a bunch of results from a database SELECT using the
I am trying to INSERT some data in ms access database using jsp but
I am trying to insert data into MS Access DB using Servelts ( PreparedStatement
I am trying to populate Select using knockout data-bind option for a list of
I'm trying to execute a query using a PreparedStatement in Java. I am getting
I am trying to select records that have the curent month using: SELECT *
I m trying to select rows/columns using vba. I want to pass row numbers
i am trying to create a dynamic multioption select using dynamic values for a
I am trying to select the last record from a table in MySQL using

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.