Arnab Bhagabati
Arnab Bhagabati

Reputation: 2715

What will happen to the insert statement if there is a SQLException?

Lets say I have a JDBC code like:

public insertdata(Long long1,String val1,) throws SQLException{

   String sql = "Some insert statement";        
   PreparedStatement ps = conn.prepareStatement(sql);
    try{

        ps.setLong(1, long1);
        ps.setString(2, val1);       
        ps.executeUpdate();
    }finally
    {

    }
}

In this case, if there is some SQLException in the try block, what willl hapeen to the insert?
Is the result "Undefined" or "Insert is aborted" ?

Apologies if its duplicate, please point me to existing questions if any.

Upvotes: -1

Views: 66

Answers (1)

Amatya Annamaneni
Amatya Annamaneni

Reputation: 27

Insert Statement is not even executed if exception is thrown before executeUpdate() call.

If the exception thrown while executeUpdate() call, data is not inserted/updated, as theres a sql exception.

Upvotes: 1

Related Questions