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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T09:33:53+00:00 2026-06-01T09:33:53+00:00

I have a method which does a simple mysql insert, when I tried to

  • 0

I have a method which does a simple mysql insert, when I tried to rollback the insert action as follow, on an error but it is not rollingback on errors, please assist me,

public void addFamer(FamerDTO famer) throws Exception {
        Connection con = JDBCConnectionPool.getInstance().checkOut();
        con.setAutoCommit(false);

        try {


            String generalFamerDataSQL = "INSERT INTO famers(famer_code, name_wt_initials, full_name, gender, "
                    + "nic_or_passport_no, sc_possition, phone_home, phone_mobile, phone_office) VALUES(?,?,?,?,?,?,?,?,?)";
            PreparedStatement insertFamerPS = con.prepareStatement(generalFamerDataSQL, PreparedStatement.RETURN_GENERATED_KEYS);
            insertFamerPS.setString(1, famer.getFamerCode());
            insertFamerPS.setString(2, famer.getNameWithInitials());
            insertFamerPS.setString(3, famer.getNameInFull());
            insertFamerPS.setString(4, famer.getGender());
            insertFamerPS.setString(5, famer.getNICorPassportNo());
            insertFamerPS.setString(6, famer.getSocietyPosission());
            insertFamerPS.setString(7, famer.getHomePhone());
            insertFamerPS.setString(8, famer.getMobilePhone());
            insertFamerPS.setString(9, famer.getOfficePhone());
            insertFamerPS.execute();   


String famerRelations = "INSERT INTO org_reg_blk_soc_fmr(org_id, region_id, famer_id, block_id, soc_id) "
                    + "VALUES (?,?,?,?,?)";
            PreparedStatement famerRelationsPS = con.prepareStatement(famerRelations);
            famerRelationsPS.setInt(1, famer.getOrganization().getOrg_id());
            famerRelationsPS.setInt(2, famer.getRegion().getRegion_id());
            famerRelationsPS.setInt(3, famerID);
            famerRelationsPS.setInt(4, famer.getBlock().getBlockId());
            famerRelationsPS.setInt(6, famer.getSociety().getSoc_id()); //intentionally made an error here to test, put index as 6 for 5
            famerRelationsPS.execute();


            con.commit();
        } catch (Exception e) {
            if (con != null) {
                logger.info("Rolling back!");
                con.rollback();                    
            }
            logger.error(e.getLocalizedMessage());

        } finally {
            con.setAutoCommit(true);
            JDBCConnectionPool.getInstance().checkIn(con);
        }

    }

once this method is called with the required parameters as there is a error in the second insert statement I expected to rollback the first insert action. but thought the error is shown, a record is added to the data base by the first insert statement.

  • 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-01T09:33:55+00:00Added an answer on June 1, 2026 at 9:33 am

    Just to check – what is the table type you’re using? Last time I used MySQL, MyISAM tables didn’t support transactions, meaning you have to used another table type e.g. InnoDB.

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

Sidebar

Related Questions

I have this method which does certain checks and applies a color code on
I have a user control which does some validation in the ValidateChildren method which
Does a method which I check for with respondsToSelector have to actually exist? What
Does anyone have any advice on which method is better when caching data in
I have an method which save files to the internet, it works but just
I have a method which takes params object[] such as: void Foo(params object[] items)
I have a method which should be executed in an exclusive fashion. Basically, it's
I have a method which is given the parameter bool sortAscending. Now I want
I have a method which should be delayed from running for a specified amount
I am developing a library for Android applications which does not use native code

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.