0
我的Sql代码在sql server中完美工作,但是当我使用我的Java代码时,它会在主表中更改不应更改的主表中的值。代码是接受发动机号码并搜索车辆表以查看它是否可用,如果不可用,将通过它的状态来指示它,然后将其返回到车辆返回表搜索它。如果在可用的表格中找到该表格,则应该更新表格,如果没有找到,那么将显示错误消息,但是其仅仅更新车辆表格,即使它不应该被更新并且当无效的时候也不发送错误消息发动机号码发送为什么我的Java代码会覆盖我的sql代码?
我的SQL代码:
ALTER procedure outbound
(
@eng VARCHAR(25)
)
AS
BEGIN
DECLARE @ENG1 VARCHAR(25)
DECLARE @ENG2 VARCHAR(25)
DECLARE @ENG3 VARCHAR(25)
SET @[email protected]
SELECT @ENG2= Engine_num from Vehicle_retuns where [email protected] and Status=1
select @ENG3=Engine_num from Vehicle where [email protected] and Status=1
IF (@[email protected])
BEGIN
UPDATE Vehicle SET Description_of_Vehicle='Vehicle have been sent back to the manufactory',Status=0 where [email protected]
/*SELECT'Vehicle have been sent back to the manufacture'*/
RETURN (1)
END
ELSE IF(@[email protected])
BEGIN
UPDATE Vehicle_retuns SET purpose ='Vehicle have been sent back to the manufactory',Status=0 where [email protected]
/*SELECT'Vehicle have been sent back to the manufacture'*/
RETURN (2)
END
ELSE
BEGIN
/*SELECT'THIS ENGINE NUMBER IS EITHER NOT IN THE DATABASE OR INCORRECT'*/
RETURN (3)
END
END
Java代码:
public static void outbound(String Eng_num, Connection con)
{
try
{
CallableStatement cs = con.prepareCall("{Call outbound(?)}");
cs.setString(1, Eng_num);
// cs.executeQuery();// excutequery is used to return object from the database
int i = cs.executeUpdate();
if(i==1)
{
System.out.println("Vehicle have been sent back to the manufacture");
}//end of if
else if(i==2)
{
System.out.println("Vehicle have been sent back to the manufacture");
}//end of else if
else if(i==3)
{
System.out.println("THIS ENGINE NUMBER IS EITHER NOT IN THE DATABASE OR INCORRECT");
}//end of else if
}// end of try
catch(Exception e)
{
e.printStackTrace();
}//end of catch
}//end of out bound
有人能告诉我是什么问题,如何解决呢?
请更具体地了解您不喜欢的行为。 – RealSkeptic