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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T03:05:57+00:00 2026-05-16T03:05:57+00:00

I use Java to do some SQL queries. in general the queries that i

  • 0

I use Java to do some SQL queries.

in general the queries that i want to perform are:

set @uid=?; set @friendsList=?; IF EXISTS(select 1 from fb_user_friends join fb_user on " +
              " fb_user.id = fb_user_friends.fb_user_id where uid=@uid)  then " +
              "update fb_user_friends set friends = @friendsList; ELSE insert " +
              "into fb_user_friends(fb_user_id,friends) values(@uid,@friendsList); END IF;

I get the MySQL Connection using:

            Class.forName("com.mysql.jdbc.Driver").newInstance();
            this._sqlconn = DriverManager.getConnection(this._url,this._userName,this._password);

and I try to execute the following code:

  String sql="set @uid=?; set @friendsList=?; IF EXISTS(select 1 from fb_user_friends join fb_user on " +
              " fb_user.id = fb_user_friends.fb_user_id where uid=@uid)  then " +
              "update fb_user_friends set friends = @friendsList; ELSE insert " +
              "into fb_user_friends(fb_user_id,friends) values(@uid,@friendsList); END IF;";
      try {
          PreparedStatement stmt = this._sqlconn.prepareStatement(sql);
          stmt.setLong(1,uid);
          stmt.setString(2,StringUtils.join(friendsList.toArray(), ','));
          stmt.executeUpdate();
      }catch (SQLException e) ....

I get the exception:

class com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'set @friendsList='110633,2018837,6813007,8803501,10711399,500061635,500214841,50'

can’t I run several commands with prepareStatement ?

Do i need to find a different approach to set the MySQL variables uid and friendsList?

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-05-16T03:05:57+00:00Added an answer on May 16, 2026 at 3:05 am

    That looks a bit like a mysql stored procedure to me? If I’m not mistaken, you should register that in mysql directly. That way, you’re able to call it using your prepared statement.

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

Sidebar

Related Questions

Im a getting errors from some code developed in Java that want to use
I have some existing code that accepts a java.sql.ResultSet that contains info retrieved from
In Java we use System.setProperty() method to set some system properties. According to this
I recently wrote some data access methods (plain old Java) that use immutable objects
I have some Java objects that I want to transform to XML. Some of
Does exists a java library that can create sql statements? I'm not in search
I am starting to use some Java code which was written by someone else.
I am taking a software engineering course and we use Java to implement some
When I tried to compile (use javac)some java sources files include a comment line
I use an xe:objectData as a datasource for a xp:dataTable. objectData1 uses some Java

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.