Recent Posts
- NCC Punjab LDC Results 2013 NCCPunjab.com Interview Selected Candidates List
- RGUHS PGSSET Super Speciality 2013 Exam www.logisys.net.in Online Application
- RKCL RS-CIT Results 2013 rkcl.in RSCIT Final Exam May Result 2013
- TNEB Electricity Bills Online Payment tnebnet.org/awp/login Tamilnadu EB Payment System
- Kerala LET 2013 Fee Structure for 2013-14 Engineering College Admission
Discussion Forum
Transaction in Java With Example
Transaction Resultset in Java With Example. This Java Transaction example describes the basic operations performed on the Transaction database connectivity code.
Transaction Resultset in Java With Example. This Java Transaction example describes the basic operations performed on the Transaction database connectivity code.In this example you will learn about how to write java code for Transaction with oracle database.
Program:
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
public class TransactionDemo {
public static void main(String args[]){
Connection con=null;
Statement st = null;
try {
Class.forName(“oracle.jdbc.driver.OracleDriver”);
con=DriverManager.getConnection(“jdbc:oracle:thin:@localhost:1521:ORCL”,”scott”,”tiger”);
con.setAutoCommit(false);
st = con.createStatement();
st.executeUpdate(“delete from eshusoft where username=’myuser’”);
System.out.print(“Do U want to delete(yes/no):”);
String ch = new BufferedReader(new InputStreamReader(System.in)).readLine();
if(ch.equalsIgnoreCase(“yes”)){
con.commit();
System.out.print(“rows is deleted”);
} else if(ch.equalsIgnoreCase(“no”)){
con.rollback();
System.out.print(“rows is not deleted”);
}
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
Result:
Do you want to delete(yes/no) : yes
row is deleted
