spring+hibernate 向数据库提交语句出现乱码
Hibernate:selecttype0_.type_idastype1_,type0_.type_nameastype2_5_fromonline.typetype0...
Hibernate: select type0_.type_id as type1_, type0_.type_name as type2_5_ from online.type type0_ where type0_.type_name='???ú'
Hibernate: insert into online.type (type_name, type_id) values (?, ?)
Hibernate: select type0_.type_id as type1_, type0_.type_name as type2_5_ from online.type type0_ where type0_.type_name='???ú'
2015-7-20 23:02:36 org.apache.catalina.core.StandardWrapperValve invoke
严重: Servlet.service() for servlet action threw exception
java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
at java.util.ArrayList.RangeCheck(ArrayList.java:547)
at java.util.ArrayList.get(ArrayList.java:322)
at com.DAO.ProductDAO.getId(ProductDAO.java:17)
上面是错误提示
下面是出错的地方(如果传入的是中文就会出现上面的错,英文就不会)
public Type getId(String t){
@SuppressWarnings("unchecked")
List<Type> typeId = this.getHibernateTemplate().find("from Type where typeName = '"+t+"'");
Type ty = typeId.get(0);
return ty;
}
单独打印出传入的 t 无论中英文都是对的
改hibernate.cfg.xml文件中
<property name="hibernate.connection.url">jdbc:mysql://localhost:3306/online?useUnicode=true&characterEncoding=UTF8</property>
已试过无用···求教各位大神! 展开
Hibernate: insert into online.type (type_name, type_id) values (?, ?)
Hibernate: select type0_.type_id as type1_, type0_.type_name as type2_5_ from online.type type0_ where type0_.type_name='???ú'
2015-7-20 23:02:36 org.apache.catalina.core.StandardWrapperValve invoke
严重: Servlet.service() for servlet action threw exception
java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
at java.util.ArrayList.RangeCheck(ArrayList.java:547)
at java.util.ArrayList.get(ArrayList.java:322)
at com.DAO.ProductDAO.getId(ProductDAO.java:17)
上面是错误提示
下面是出错的地方(如果传入的是中文就会出现上面的错,英文就不会)
public Type getId(String t){
@SuppressWarnings("unchecked")
List<Type> typeId = this.getHibernateTemplate().find("from Type where typeName = '"+t+"'");
Type ty = typeId.get(0);
return ty;
}
单独打印出传入的 t 无论中英文都是对的
改hibernate.cfg.xml文件中
<property name="hibernate.connection.url">jdbc:mysql://localhost:3306/online?useUnicode=true&characterEncoding=UTF8</property>
已试过无用···求教各位大神! 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询