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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T13:13:25+00:00 2026-06-13T13:13:25+00:00

class User { public static void main(String arg[]) throws SQLException { Connection con =

  • 0

class User {

public static void main(String arg[]) throws SQLException {
    Connection con = DBConnect.getConnection();
    con.setAutoCommit(false);
    PreparedStatement pstmt;
    System.out.println(con.getMetaData().supportsSavepoints()); // true
    try {
        pstmt = con.prepareStatement("insert into emp(emp_id, emp_name, salary, address, contact_number)values(?,?,?,?,?)");
        pstmt.setInt(1, 1);
        pstmt.setString(2, "a");
        pstmt.setDouble(3, 8);
        pstmt.setString(4, "s");
        pstmt.setInt(5, 9);
        pstmt.executeUpdate();
        con.commit();
        Savepoint sp = con.setSavepoint();
        if (myMethod(con)) {
            /**
             * I want to rollback the nested transaction if any error occur
             */
            con.rollback(sp);
        }
    } catch (SQLException e) {
        e.printStackTrace();
    }
}

public static boolean myMethod(Connection con) throws SQLException {

    PreparedStatement pstmt;
    try {
        pstmt = con.prepareStatement("insert into emp(emp_id, emp_name, salary, address, contact_number)values(?,?,?,?,?)");
        pstmt.setInt(1, 2);
        pstmt.setString(2, "G");
        pstmt.setDouble(3, 8);
        pstmt.setString(4, "G");
        pstmt.setInt(5, 10);
        pstmt.executeUpdate();
        con.commit();
    } catch (SQLException e) {
        e.printStackTrace();
    }
    return true;
}

}

In the above code I want to rollback the nested transaction if any condition would fail . I have created a savepoint just after committing first transaction.I am getting an exception

java.sql.SQLException: SAVEPOINT _667166fe_13ab4b3e3de__8000 does not exist
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2928)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1571)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1666)
at com.mysql.jdbc.Connection.execSQL(Connection.java:2988)
at com.mysql.jdbc.Statement.executeUpdate(Statement.java:935)
at com.mysql.jdbc.Statement.executeUpdate(Statement.java:873)
at com.mysql.jdbc.Connection.rollback(Connection.java:4777)
at com.User.main(User.java:31)

I would like to know whether the nested transaction will rollback or not ?

  • 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-13T13:13:26+00:00Added an answer on June 13, 2026 at 1:13 pm

    Since you are already calling con.commit(); before and after(in myMethod() method) Savepoint sp = con.setSavepoint();, there is no savepoint and hence complaining.

    COMMIT removes all the save points. Please refer documentation here:

    1. Oracle SAVEPOINT Statement
    2. SQLite Save Point

    Please remove the commit call, if you want to set a save point.

    In the current state of your code, there is no rollback possible as all transactions are committed, if successful.

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

Sidebar

Related Questions

Consider the following code: class Sample{ public static void main(String args[]){ String text1=C:\Documents\User\sample; String
import java.io.*; import java.util.StringTokenizer; class FileCopy { public static void main(String[] args) throws IOException
I run this code: public class User { public static void main(String args[]) {
import java.util.*; public class oddNumbers { public static void main(String[] args) { System.out.println(enter two
Here is my code. import java.util.Scanner; public class ORR_P02 { public static void main(String
public class InterruptedInput { public static void main(String[] args) { InputThread th=new InputThread(); //worker
public class Db_try1 { public static void main(String[] args) { String driver=oracle.jdbc.OracleDriver; String url=jdbc:oracle:thin:@localhost:1521:xe;
import java.util.Scanner; public class MatchesMethodTest { public static void main(String[] args) { String s;
I have this user defined function. public partial class UserDefinedFunctions { static int i;
I have this Class: public class User { public string id{ get; set; }

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.