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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T02:47:34+00:00 2026-06-01T02:47:34+00:00

Given following Statment: String query = "Select * from T_spareParts where SparePartPK IN (?

  • 0

Given following Statment:

 String query = "Select * from T_spareParts where SparePartPK IN (? )"

In my BackBean (JSF 2) I first iterate through all cars in table and build a String of all the cars currently selected (by picking each cars ID as primary key) so the final String before being passed to SQL could look like:

String finalString = " '1','2','3','4'";

And then :

this.prepareStatement= this.connection.prepareStatement(query);
this.prepareStatement.setString(1,finalString);
this.prepareStatement.executeQuery();

Exception thrown is:

Error converting data type nvarchar to bigint.

Now my understanding is that exception is due to SparePartPK is type bigint and we’re passing a String .

But in SQL Server (2008) i can do :

 Select * from T_spareParts where SparePartPK IN ('1','2','3','4')"

which returns results as expected. Why am i getting the exception and how can i correct the issue? (also feel free to comment if this isn’t the best approach)

Update:

I’ve also tried to produce the finalString without single quotes which causes the same exception to be thrown :

String finalString = " 1,2,3,4";
  • 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-01T02:47:35+00:00Added an answer on June 1, 2026 at 2:47 am

    Thanks for the suggestions. Though as an alternative I created a StoredProcedure where it takes one parameter and inside the StoredProcedure i run the above Query in question formulating the IN section using the passed parameter .

    So all above code still applies, The parameter passed to the storeDProcedure is one String separated by , without the single quotes.

    Might not be the optimum answer but works quit well 🙂 .

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

Sidebar

Related Questions

Consider this: //members is a table. String sql=select * from members; Query query =
Given the following XML: <current> <login_name>jd</login_name> </current> <people> <person> <first>John</first> <last>Doe</last> <login_name>jd</login_name> </preson> <person>
Given I have data like the following, how can I select and group by
Given public String(char*) why we cannot use the following statement? string str = new
Given the following code: if (string) { console.log('true!'); } //logs true to the console
Given the following routine: private static object ParseNumber(string token, FieldDefinition def) { if (def.Fraction
Given the following POCO Code First Entities public class Customer { public int CustomerId
I have the following code for SQLite: std::vector<std::vector<std::string> > InternalDatabaseManager::query(std::string query) { sqlite3_stmt *statement;
Updated question: Django is giving me the following sql query: SELECT auth_user.id, auth_user.username, auth_user.first_name,
How can you write the following statement in the given languages? a(0) = 1

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.