You have an error in your SQL syntax;

问题描述(更新测试失败)

org.apache.ibatis.exceptions.PersistenceException:

Error updating database. Cause: java.sql.SQLSyntaxErrorException: 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 ‘id=4’ at line 1

The error may exist in cn/js/ccit/mapper/CustomerMapper.java (best guess)

The error may involve cn.js.ccit.mapper.CustomerMapper.updateCustomer-Inline

The error occurred while setting parameters

SQL: update t_customer set username=?, jobs=?,phone=?,login_Account=?where id=?

Cause: java.sql.SQLSyntaxErrorException: 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 ‘id=4’ at line 1

@Update("update t_customer set username=#{username}, jobs=#{jobs},phone=#{phone},login_Account=#{loginAccount}"
			+"where id=#{id}")
	int updateCustomer(Customer customer);//更新一个用户
@Test
	public void updateTest() throws IOException {
		// 2.获取和数据库的一次会话
		SqlSession sqlSession = sqlSessionFactory.openSession();
		try {
			// 3.使用sqlSession操作数据库,获取到dao接口的实现
			CustomerMapper mapper = sqlSession.getMapper(CustomerMapper.class);
			// 4.调用之前定义的方法
			int updateCustomer = mapper.updateCustomer(new Customer(4, null, null, "88888888888",null));
			System.out.println(updateCustomer);
			sqlSession.commit();
		} finally {
			sqlSession.close();
		}

	}

原因分析:

缺少空格
在这里插入图片描述

解决方案:

@Update("update t_customer set username=#{username}, jobs=#{jobs},phone=#{phone},login_Account=#{loginAccount} "
			+"where id=#{id}")
	int updateCustomer(Customer customer);//更新一个用户
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值