作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
尝试向数据库中插入数据。每次都显示这个错误
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
最佳答案
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/
我需要获取最早日期的起始余额和月末的期末余额,并按 stock_id 分组。我的 table : id stock_id balance transact_at 1 1
尝试向数据库中插入数据。每次都显示这个错误 com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error i
我是一名优秀的程序员,十分优秀!