instrument_borrowing.instrument_borrowing_id="+max).replaceAll("<","<"); select = service.runCountSql(sql); Integer count = Integer.valueOf(String.valueOf(select.getSingleResult())); if(count>0){ sql = "delete from "+"instrument_borrowing"+" WHERE "+"instrument_borrowing_id"+" ="+max; select = service.runCountSql(sql); select.executeUpdate(); return error(30000,"仪器不足"); } sql = "UPDATE `instrument_information` INNER JOIN `instrument_borrowing` ON instrument_information.instrument_number=instrument_borrowing.instrument_number SET instrument_information.number_of_instruments= instrument_information.number_of_instruments - instrument_borrowing.borrowed_quantity WHERE instrument_borrowing.instrument_borrowing_id="+max; select = service.runCountSql(sql); select.executeUpdate(); return success(1); } }
时间: 2024-02-29 17:55:21 浏览: 74
这是一个使用 Spring Boot 框架的归还仪器接口,使用了 @PostMapping 注解表示这是一个处理 POST 请求的方法。方法内部首先获取最大的仪器借用记录编号 max,并将其替换为正确的格式。然后根据仪器借用记录编号查询数据库中是否存在该记录,如果不存在则返回错误信息。
接着,如果仪器数量不足,则删除该仪器借用记录并返回错误信息;否则,将仪器数量更新,并返回成功的信息。
其中,error 和 success 方法用于返回统一的错误和成功信息。而 runCountSql 方法用于执行 SQL 语句并返回查询结果。同时,需要注意 SQL 语句中使用了 INNER JOIN 进行连接表操作。
相关问题
create trigger tri_jieshu on reader_borrow for insert as declare @id varchar(50) select @id=borrow_id from inserted update book_borrowing set book_surplus=book_surplus-1 where book_id=@id create trigger tri_huanshu on reader_back for insert as declare @id varchar(50) select @id=back_id from inserted update book_borrowing set book_surplus=book_surplus+1 where book_id=@id create proc payment @id varchar(20),@name varchar(20) as begin select borrow_date,back_date from reader_back,reader_borrow where back_id=borrow_id and back_id=@id and borrow_bookname=back_bookname and (select datediff(day, borrow_date,back_date) FROM reader_back,reader_borrow)>7 end create view view_pay as select * from reader_back,reader_borrow where (borrow_id=back_id and borrow_bookname=back_bookname) create proc proc_pay (@id varchar(20)) as select back_id,back_bookname,back_date,borrow_date from view_pay where back_id=@id exec proc_pay @id='1'该代码有什么语法错误
在触发器 tri_jieshu 和 tri_huanshu 中,update 语句中的 where 子句需要指定 book_id 而不是 borrow_id 和 back_id。应该修改为:
```
update book_borrowing set book_surplus=book_surplus-1 where book_id=(select book_id from inserted)
```
和
```
update book_borrowing set book_surplus=book_surplus+1 where book_id=(select book_id from inserted)
```
在 payment 存储过程中,应该将 datediff 函数的返回值赋值给一个变量,然后使用该变量进行比较。应该修改为:
```
create proc payment @id varchar(20),@name varchar(20) as
begin
declare @days int
select @days = datediff(day, borrow_date,back_date) FROM reader_back,reader_borrow
where back_id=borrow_id and back_id=@id and borrow_bookname=back_bookname
if (@days > 7)
begin
select borrow_date,back_date from reader_back,reader_borrow
where back_id=borrow_id and back_id=@id and borrow_bookname=back_bookname
end
end
```
在 proc_pay 存储过程中,应该将 @id 的数据类型修改为 varchar(50),并且在查询结果中使用别名来避免列名冲突。应该修改为:
```
create proc proc_pay (@id varchar(50)) as
begin
select b.back_id, b.back_bookname, b.back_date, r.borrow_date
from reader_back b, reader_borrow r
where b.back_id = r.borrow_id and b.back_id = @id and b.borrow_bookname = r.back_bookname
end
exec proc_pay @id='1'
```
public class BorrowSQL { ConnectionSQL borCon = new ConnectionSQL(); //判断是否超出借阅数量限制 public int check(Borrow r) { int borrowing = -1; try{ borCon.connectDB(); String sql = "select COUNT(readerID) from borrow where readerID=" + r.getID(); borCon.statement = borCon.connection.prepareStatement(sql); borCon.resultSet = borCon.statement.executeQuery(sql); if(borCon.resultSet .next()){ borrowing = borCon.resultSet .getInt("COUNT(readerID)"); } } catch (SQLException throwable) { throwable.printStackTrace(); }finally { borCon.close(); } return borrowing; }翻译一下这段代码
这段代码定义了一个名为BorrowSQL的类,其中包含一个名为borCon的ConnectionSQL对象。该类还有一个名为check的方法,其参数为一个Borrow对象,返回一个整数类型的值。该方法的作用是连接到数据库,执行查询语句以获取指定读者已借阅的数量,然后将其返回。如果在查询过程中发生异常,则将其打印出来。无论是否发生异常,最终都会关闭连接。
阅读全文
相关推荐
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![docx](https://img-home.csdnimg.cn/images/20241231044901.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![doc](https://img-home.csdnimg.cn/images/20241231044833.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)