踩坑笔记

编程开发,时刻踩坑时刻记录,再踩就是傻子!

1.数据库中有值,但是Java代码取不出:

原因可能POJO或者domain里的类中的变量名称与数据库字段名不匹配。这里我的domain中有个User类,它的变量名及其方法为username,而数据库中为name

2.使用C3P0和DBUtil向数据库插入数据时,插入前是中文,而数据库中是乱码???,:

原因:C3P0配置文件

解决方法:手动设置C3P0配置文件,访问数据库编码为utf-8,再url中这样写

<property name="jdbcUrl">jdbc:mysql://localhost:3306/cuzudb?characterEncoding=utf8</property>

3.写的JQ语句怎么都不执行:原因页面未导入JQjar包

4.报这个错

java.lang.NumberFormatException: For input string: "img"

我是因为,传到jsp的是一个List集合,我直接想获得list集合里边的对象的某个属性,却把这个List集合当成了里边的对象,直接使用了${animals.img},而应该使用jstl的foreach  循环获得对象

5.报这个错:Server Tomcat v7.0 Server at localhost failed to start.

解决:去web.xml中,有的servlet的url-pattern没有加/,例如这样

6.使用DBUtil   c3p0连接池  来进行数据库查询,数据库编码utf-8,客户端编码utf-8,中文模糊查询没有结果的解决方法

手动配置连接池连接数据库编码

就加上红框里的东西,注意修改数据库名称

<property name="jdbcUrl">jdbc:mysql://localhost:3306/ajax?characterEncoding=UTF-8</property>

7.hibernate异常:InvocationTargetException或者

org.hibernate.internal.util.config.ConfigurationException: Unable to perform unmarshalling at line number 0 and column 0 in RESOURCE hibernate.cfg.xml. Message: null

原因:配置文件出错!

8.hibernate异常:org.hibernate.MappingException: Repeated column in mapping for entity: com.yl.domain.Province column: pro_id (should be mapped with insert="false" update="false")

这里出现异常的原因是,我的主键是pro_id而又设置了外键pro_id,导致两者冲突

9.hibernate异常:org.hibernate.exception.ConstraintViolationException: could not execute statement

原因:运行了一次hibernate,然后已经在数据库中建表了,然后修改了一些字段,然后再次运行hibernate就报错,因为字段不匹配

解决,删表重建

 


  

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值