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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T22:33:03+00:00 2026-06-13T22:33:03+00:00

I am trying to commit a sql transaction to MySQL but I get myself

  • 0

I am trying to commit a sql transaction to MySQL but I get myself past an MySQLSyntaxErrorException.

The code I am using is:

implicit connection => 
        SQL("""
            start transaction;
            insert into projects(id_user, name, description) values({idUser}, {name}, {description});
            set @last_id = last_insert_id();
            insert into assigned(id_user, id_project) values({idUser}, @last_id);
            commit;
        """)
    .on('idUser -> idUser,
        'name -> project.name,
        'description -> project.description
    ).execute()  

The exception I get:

[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 'insert into projects(id_user, name, description) values(1, 'First inserted proje' at line 1]  

I am starting to think that I can’t execute such statements at all with Anorm.

  • 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-13T22:33:04+00:00Added an answer on June 13, 2026 at 10:33 pm

    You cannot use transaction that way. You have to understand that anorm is simply a wrapper around existing jdbc libraries. By default, when using the withConnection and SQL :

    DB.withConnection { conn => 
        SQL("...
    }
    

    Your query is transformed using a PreparedStatement. Meaning the ; chars are causing errors.

    Thus, if you want to use transaction, you have to use anorm’s mecanism for that.

    DB.withTransaction { conn =>
        SQL("...
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to commit a *.csproj file using Tortoise SVN, but get: Commit Failed!
I'm trying to do the following transaction using Linq to sql. but the id
I'm trying to do a two-phase commit using SQLalchemy 0.6.8 with Postgresql 8.3.4, but
I'm trying to execute my simple SQL code to create a table. BEGIN TRANSACTION;
Using a heterogenous connection from Oracle 11gr2 to Sql Server 2005, we are trying
I'm trying to commit a transaction to my Sql Server 2008 database - firstly
I am trying to do a simple commit in SVN (I'm using Cornerstone on
I am trying to get a post-commit.bat script running on a Windows Vista Ultimate
I'm trying to get my commit-build.bat to execute other .BAT files as part of
I am trying to set up a MySQL transaction such that I can loop

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.