在jsp页面中使用Transaction查询

时间:2014-12-16 10:13:21

标签: sql jsp

我在jsp页面中使用以下查询。但我不确定在jsp页面中使用此查询是否属实。

int i = st.executeUpdate("'BEGIN TRANSACTION DECLARE @id [int] SELECT @id = SCOPE_IDENTITY() INSERT INTO  Viewer(Reserve_ID, F_Name, L_Name, Competition_ID, City, Phone, [E-mail]) VALUES (@id, '" + fname + "','" + lname + "','" + 30 + "','" + city + "','" + phone + "','" + email + "' ) INSERT INTO  Reservation_Inf(Reservation_Date, Competition_ID, NumberOfTicket, Position_ID) VALUES ('" + dNow + "','" + 30 + "','" + 1 + "','" + 8 + "' ) COMMIT TRANSACTION '" );

if (i > 0) {
   response.sendRedirect("Success.jsp");
} else {
   response.sendRedirect("Fail.jsp");
}

它给出了这个错误:

 Incorrect syntax near 'BEGIN TRANSACTION DECLARE @id [int] SELECT @id = SCOPE_IDENTITY() INSERT INTO  Viewer(Reserve_ID, F_Name, L_Name, Competition_ID,'.

0 个答案:

没有答案