[英]why does my Java code override my sql code?
我的Sql代碼在sql服務器中可以完美地工作,但是當我使用Java代碼時,它應該在不更改的情況下更改主表中的值。 該代碼是接受發動機號並在車輛表中進行搜索以查看其是否可用,如果不可用則由其狀態指示,然后轉到車輛返回表中進行搜索。 如果在可用表中找到該表,則應更新該表(如果未找到該表),則會顯示一條錯誤消息,但即使該表不應該更新,它也僅更新車輛表,並且在無效時也不發送錯誤消息引擎號已發送
我的SQL代碼:
ALTER procedure outbound
(
@eng VARCHAR(25)
)
AS
BEGIN
DECLARE @ENG1 VARCHAR(25)
DECLARE @ENG2 VARCHAR(25)
DECLARE @ENG3 VARCHAR(25)
SET @ENG1=@eng
SELECT @ENG2= Engine_num from Vehicle_retuns where Engine_num=@eng and Status=1
select @ENG3=Engine_num from Vehicle where Engine_num=@eng and Status=1
IF (@eng=@ENG3)
BEGIN
UPDATE Vehicle SET Description_of_Vehicle='Vehicle have been sent back to the manufactory',Status=0 where Engine_num=@ENG3
/*SELECT'Vehicle have been sent back to the manufacture'*/
RETURN (1)
END
ELSE IF(@eng=@ENG2)
BEGIN
UPDATE Vehicle_retuns SET purpose ='Vehicle have been sent back to the manufactory',Status=0 where Engine_num=@ENG2
/*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
有人可以告訴我問題是什么以及如何解決?
您的主要問題是CallableStatement.executeUpdate()返回:
(1)SQL數據操作語言(DML)語句的行計數,或者(2)SQL語句不返回任何內容的行數
您似乎期望它返回outbound
過程的結果,但事實並非如此。
您可能會發現這很有趣。 似乎建議您可以使用InOutParam
返回值,但我從未使用過該技術。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.