deleting row

i have used following query for delete a row in the tables.

but its not deleting. help me

String action = request.getParameter("action");

if (action != null && action.equals("delete")) {

conn.setAutoCommit(false);

PreparedStatement pstatement = conn.prepareStatement("DELETE FROM sec_mast WHERE sec_no=?,vou_no=?");

PreparedStatement pstatement1 = conn.prepareStatement("DELETE FROM sec_detail WHERE sec_no=?,vou_no=? ");

pstatement.setInt(1,Integer.parseInt(request.getParameter("sec_no")));

pstatement1.setInt(1,Integer.parseInt(request.getParameter("sec_no")));

pstatement.setString(2,request.getParameter("vou_no"));

pstatement1.setString(2,request.getParameter("vou_no"));

int rowCount = pstatement.executeUpdate();

int rowCount1 = pstatement1.executeUpdate();

conn.setAutoCommit(false);

conn.setAutoCommit(true);

}

ResultSet rs = statement.executeQuery

("select * from sec_mast,sec_detail where sec_mast.vou_no=sec_detail.vou_no ");

my database table is follow:

SQL> descr sec_mast;

Name Null?Type

-- -- --

SEC_NONOT NULL NUMBER(4)

CATG_CODENUMBER(2)

FACE_VAL NOT NULL NUMBER(10,2)

PUR_VALNOT NULL NUMBER(10,2)

INT_PAID NOT NULL NUMBER(8,2)

INT_RECD NOT NULL NUMBER(8,2)

BRKR NOT NULL NUMBER(8,2)

TOT_VALNOT NULL NUMBER(12,2)

VOU_NO VARCHAR2(9)

VOU_DATEDATE

VOU_AMTNUMBER(15,2)

DUE_DATE1 NOT NULL DATE

DUE_DATE2DATE

LF_NO NOT NULL VARCHAR2(10)

MAT_DATE NOT NULL DATE

FK_VOU_NO2VARCHAR2(9)

SQL> descr sec_detail;

Name Null?Type

-- -- --

SEC_NO NUMBER(4)

LF_NO VARCHAR2(8)

DUE_DATE1DATE

VOU_NO VARCHAR2(9)

VOU_DATEDATE

VOU_AMTNUMBER(15,2)

FK_VOU_NO1VARCHAR2(9)

[1900 byte] By [abhit_kumara] at [2007-10-1 1:14:21]
# 1
and its coming error:ORA-02292: integrity constraint (SCOTT.FK_SEC_LF) violated - child record found
abhit_kumara at 2007-7-8 1:30:40 > top of Java-index,Security,Event Handling...
# 2
You have not commited the update. Try replacingconn.setAutoCommit(false);conn.setAutoCommit(true);with conn.commit()You should also think about doing a rollback() if there is an exception anywhere.
sabre150a at 2007-7-8 1:30:40 > top of Java-index,Security,Event Handling...
# 3

You may also want to reverse these two lines:

int rowCount = pstatement.executeUpdate();

int rowCount1 = pstatement1.executeUpdate();

You want to delete the detail records before the master if your have foreign key constraints. I dont think wrapping this in a transaction will protect you.

Peter

Peter_VC2a at 2007-7-8 1:30:40 > top of Java-index,Security,Event Handling...