[英]why does my Java code override my sql code?
My Sql code works perfectly in sql server but when I use my Java code it changes values in the main table when it should not be changing. 我的Sql代码在sql服务器中可以完美地工作,但是当我使用Java代码时,它应该在不更改的情况下更改主表中的值。 the code is to accept an engine number and search through a vehicle table to see if it's available which would be indicated by it's status if not available it would then go to the vehicle return table search for it. 该代码是接受发动机号并在车辆表中进行搜索以查看其是否可用,如果不可用则由其状态指示,然后转到车辆返回表中进行搜索。 if found in the table to which it was available the table should be updated if not found then an error message would be displayed but its only updating the vehicle table even when it shouldn't be updating and also not sending the error message when an invalid engine number is sent 如果在可用表中找到该表,则应更新该表(如果未找到该表),则会显示一条错误消息,但即使该表不应该更新,它也仅更新车辆表,并且在无效时也不发送错误消息引擎号已发送
my sql code: 我的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 code: 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
Can someone please tell me what the problem is and how do i fix it ? 有人可以告诉我问题是什么以及如何解决?
Your main problem is that CallableStatement.executeUpdate() returns: 您的主要问题是CallableStatement.executeUpdate()返回:
either (1) the row count for SQL Data Manipulation Language (DML) statements or (2) 0 for SQL statements that return nothing (1)SQL数据操作语言(DML)语句的行计数,或者(2)SQL语句不返回任何内容的行数
You seem to expect it to return the result of your outbound
procedure, which it does not. 您似乎期望它返回outbound
过程的结果,但事实并非如此。
You may find this of interest. 您可能会发现这很有趣。 It seems to suggest you can use an InOutParam
to return values but I've never used that technique. 似乎建议您可以使用InOutParam
返回值,但我从未使用过该技术。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.