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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T22:37:29+00:00 2026-06-14T22:37:29+00:00

I have a simple database transaction like the code below. The first query should

  • 0

I have a simple database transaction like the code below. The first query should work fine while the second one should throw an exception and therefore the transaction should not go through!

The problem is, after running this code, the first query seemed to have inserted a row in my table, as if it was not transactional. The code does throw an exception and myCon.rollback(); is executed but that new row is inserted in the table anyways.

I am not sure what exactly I am missing, any hint would be highly appreciated.

— Edit: The problem was that I was using the default MyISAM engine for my table. I changed it to InnoDB and the problem was solved.

    Connection myCon = null;

    try
    {
        Class.forName("com.mysql.jdbc.Driver");
        myCon = DriverManager.getConnection (dbUrl, dbUser, dbPass);

        myCon.setAutoCommit(false); // the intention is to do a transaction

        Statement stmt = myCon.createStatement();

        String query = "INSERT INTO tbltest(f1) VALUES (1);";
        stmt.executeUpdate(query);

        query = "INSERT INTO"; // a malformed query
        stmt.executeUpdate(query);

        con.commit();
    }
    catch(Exception e)
    {
        System.err.println(e.toString());
        myCon.rollback();
    }
    finally
    {
        myCon.close();
    }
  • 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-14T22:37:30+00:00Added an answer on June 14, 2026 at 10:37 pm

    Your MySQL database has to be set up to support such a thing. I believe that means InnoDB for every table. Is that the case for your situation? If not, create InnoDB tables and try again.

    http://dev.mysql.com/doc/refman/5.0/en/commit.html

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

Sidebar

Related Questions

I have simple database - one table with 6 collumns. 3 of them i
I'm trying to run a simple insert query to a database. I have it
I have little php code for daily audit transaction.I make simple to get the
I have a simple database with multiple tables. I can't figure out how to
I have a simple database named customer with a single table data.I want to
Consider the following scenario We have a simple database that involves two entities: user
Ok, i have a simple database engine (its a proprietary product written in vb6)
I have a very simple database table that joins two other tables in a
I have completed a simple database for a project. Only 6tables. Of the 6,
I have a simple UserControl for database paging, that uses a controller to perform

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.