欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

MySQL及MyBatis问题汇总

程序员文章站 2022-04-18 14:18:29
1 外键外键必须是另一个表的主键或唯一键.int camera_id unique,int camera_infos auto_increment【参考文献】[1]https://www.cnblogs.com/liushui-sky/p/8830936.html[][]...

1 外键

1.0 外键必须是另一个表的主键或唯一键.

int goods_id unique,
int goods_infos auto_increment

1.2 同一个数据库外键命名唯一

Cannot add or update a child row: a foreign key constraint fails (peopleinfosforsb.vacancy_timers, CONSTRAINT vacancy_timers_ibfk_1 FOREIGN KEY (task_name) REFERENCES vacancy_tasks (task_name) ON DELETE CASCADE ON UPDATE CASCADE

  • 原因
    外键重名,添加或更新外键表数据时,主表中不含该外键数据.
  • 解决
    修改外键名,使同一个数据库中的表中外键名唯一.先添加主表数据,再添加子表数据.

1.3 主表先添加数据再更新子表数据

Cannot add or update a child row: a foreign key constraint fails (peopleinfosforsb.vacancy_timers, CONSTRAINT vacancy_timers_ibfk_1 FOREIGN KEY (task_name) REFERENCES vacancy_tasks (task_name) ON DELETE CASCADE ON UPDATE CASCADE

  • 原因
    添加或更新外键表数据时,主表中不含该外键数据.
  • 解决
    先添加主表数据,再添加子表数据.

2 mysql使用关键字报错

Error updating database. Cause: 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 'group, name)

  • 原因
    使用了关键字group.
  • 解决
    遇到关键字,修改.

3 mybatis找不到string

nested exception is org.apache.ibatis.reflection.ReflectionException: There is no getter for property named ‘task_name’ in ‘class java.lang.String’
-原因
未设置字符键值对.

  • 解决
    设置字符键值对.

4 mysql数据库连接失败

ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/var/run/mysqld/mysqld.sock’ (2)

5 pymysql连接失败

sqlalchemy.exc.OperationalError: (pymysql.err.OperationalError) (1045, “Access denied for user ‘root’@‘localhost’ (using password: YES)”)

6 MySQL语句执行时,Mybatis数据类型不兼容

invalid comparison: java.util.ArrayList and java.lang.String
场景:传入数据为list(Array),参数比较时,使用了字符比较
参数:List nameLis=Array.asList(“xiaoxiao”,“xiaohua”);
Mybatis比较形式:

<if test="nameLis != null and nameLis !=''">
  and name in 
  <foreach collection="nameLis" index="index" item="item" open="(" separator="," close=")">
    #{item}
  </foreach>
</if>

nameLis为List类型,而nameLis != ''是字符串比较,因此报错,
正确形式为:

<if test="nameLis != null and nameLis.size()>0">
  and name in 
  <foreach collection="nameLis" index="index" item="item" open="(" separator="," close=")">
    #{item}
  </foreach>
</if>

【参考文献】
[1]https://www.cnblogs.com/liushui-sky/p/8830936.html
[2]https://blog.csdn.net/qq_41042595/article/details/88591028
[3]https://blog.csdn.net/hmmmmm2929/article/details/93193394
[4]https://www.jianshu.com/p/9152bcbd0e91
[5]https://www.cnblogs.com/orac/p/6726323.html
[6]http://www.cnntt.com/archives/2505
[7]https://blog.csdn.net/qq_43642812/article/details/89578126
[8]https://www.cnblogs.com/zyulike/p/10542341.html

本文地址:https://blog.csdn.net/Xin_101/article/details/103062758

相关标签: # MyBatis # MySQL