gpt4 book ai didi

java - 在第 1 行的 'update, stock_id) values (0, 0.0, 10018, 1, null, 0, null, 0)' 附近使用正确的语法

转载 作者:行者123 更新时间:2023-11-29 07:37:34 24 4
gpt4 key购买 nike

尝试向数据库中插入数据。每次都显示这个错误

com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'update, stock_id) values (0, 0.0, 10018, 1, null, 0, null, 0)' at line 1

数据库

CREATE TABLE `stock_log` (   
`stock_id` int(11) NOT NULL AUTO_INCREMENT,
`added_employee` int(11) DEFAULT NULL,
`added_item` int(11) DEFAULT NULL,
`added_quantity` int(11) DEFAULT NULL,
`added-price` double DEFAULT NULL,
`supplier` int(11) DEFAULT NULL NOT,
`update` varchar(45) DEFAULT NULL,
`update_reason` varchar(45) DEFAULT NULL,
PRIMARY KEY (`stock_id`),
KEY `added_employee_idx` (`added_employee`),
KEY `added_item_idx` (`added_item`),
KEY `supplier_idx` (`employee`),
CONSTRAINT `added_employee` FOREIGN KEY (`added_employee`)
REFERENCES `employee` (`employee_id`) ON DELETE NO ACTION ON UPDATE NO ACTION,
CONSTRAINT `added_item` FOREIGN KEY (`added_item`)
REFERENCES `item_stock` (`item_id`) ON DELETE NO ACTION ON UPDATE NO ACTION,
CONSTRAINT `supplier` FOREIGN KEY (`supplier`)
REFERENCES `supplier`(`supplier_id`) ON DELETE NO ACTION ON UPDATE NO ACTION )
ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;

型号

@Entity
@Table(name="stock_log")
public class Stock {

@Id
@Column(name="stock_id")
private int stockId;
@Column(name="added_employee" )
private int employee;
@Column(name="added_item")
private int item;
@Column(name="added_quantity")
private int addQty;
@Column(name="added_price")
private double addedPrice;
@Column(name="supplier")
private int supplier;
@Column(name="update")
private String update;
@Column(name="update_reason")
private String reason;

public Stock() {
super(); // TODO Auto-generated constructor stub
}

public Stock(int stockId, int employee, int item, int addQty,
double addedPrice, int supplier, String update, String reason) {
super();
this.stockId = stockId;
this.employee = employee;
this.item = item;
this.addQty = addQty;
this.addedPrice = addedPrice;
this.supplier = supplier;
this.update = update;
this.reason = reason;
}

//getter setter

}

服务

public interface StockLogService {

void saveAStock(Stock addedStock);

}
@Service
public class StockLogServiceImp implements StockLogService {

@Resource
private StockLogRepository repository;

@Override
public void saveAStock(Stock addedStock) {
repository.saveAndFlush(addedStock);
}
}

存储库

public interface StockLogRepository extends JpaRepository<Stock, String> {   
}

Controller

@Controller 
public class CommonController {
@Autowired
SupplierService supService;
@Autowired
StockLogService stockService;
Date todayDate = Calendar.getInstance().getTime();

@RequestMapping(value="testing1")
public ModelAndView viewStock1() {
ModelAndView moView = new ModelAndView("testing1");
//Give empty stock object for ("/add")
moView.addObject("newStockCommand", new Stock());
return moView;
}
@RequestMapping(value="testing2")
public ModelAndView viewStock2(@ModelAttribute ("newStockCommand") Stock newStockCommand) {
ModelAndView moView = new ModelAndView("testing2");
moView.addObject("addedStock", newStockCommand);
stockService.saveAStock(newStockCommand);
return moView;
}
}

JSP

JSP screenshot

最佳答案

update 是关键字。尝试重命名表定义中的列

update varchar(45) DEFAULT NULL

关于java - 在第 1 行的 'update, stock_id) values (0, 0.0, 10018, 1, null, 0, null, 0)' 附近使用正确的语法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48002173/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com