Hibernate连接数据库出错 5C

为什么我的hibernate都能查询oracle数据库里面的东西,也执行了hql语句,但是在query.list()的时候会报错,是不是驱动错了?求大神指点一下啊,下面的是异常

org.hibernate.exception.GenericJDBCException: could not execute query
org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:126)
org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:114)
org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)
org.hibernate.loader.Loader.doList(Loader.java:2235)
org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2129)
org.hibernate.loader.Loader.list(Loader.java:2124)
org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:401)
org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:363)
org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:196)
org.hibernate.impl.SessionImpl.list(SessionImpl.java:1149)
org.hibernate.impl.QueryImpl.list(QueryImpl.java:102)
com.sneaker.daoimpl.CustomerDaoImpl.login(CustomerDaoImpl.java:29)
com.sneaker.service.CustomerService.login(CustomerService.java:20)
com.sneaker.action.CustomerAction.login(CustomerAction.java:42)
.....

java.sql.SQLException: ????
oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:112)
oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:146)
oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:208)
oracle.jdbc.driver.NumberCommonAccessor.throwOverflow(NumberCommonAccessor.java:7465)
oracle.jdbc.driver.NumberCommonAccessor.getInt(NumberCommonAccessor.java:103)
oracle.jdbc.driver.OracleResultSetImpl.getInt(OracleResultSetImpl.java:521)
oracle.jdbc.driver.OracleResultSet.getInt(OracleResultSet.java:1563)
org.apache.commons.dbcp.DelegatingResultSet.getInt(DelegatingResultSet.java:236)
org.hibernate.type.IntegerType.get(IntegerType.java:51)
org.hibernate.type.NullableType.nullSafeGet(NullableType.java:184)
org.hibernate.type.NullableType.nullSafeGet(NullableType.java:173)
org.hibernate.type.AbstractType.hydrate(AbstractType.java:105)
org.hibernate.persister.entity.AbstractEntityPersister.hydrate(AbstractEntityPersister.java:2114)
org.hibernate.loader.Loader.loadFromResultSet(Loader.java:1404)
org.hibernate.loader.Loader.instanceNotYetLoaded(Loader.java:1332)
org.hibernate.loader.Loader.getRow(Loader.java:1230)
org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:603)
org.hibernate.loader.Loader.doQuery(Loader.java:724)
org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:259)
org.hibernate.loader.Loader.doList(Loader.java:2232)
org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2129)
org.hibernate.loader.Loader.list(Loader.java:2124)
org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:401)
org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:363)
org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:196)
org.hibernate.impl.SessionImpl.list(SessionImpl.java:1149)
org.hibernate.impl.QueryImpl.list(QueryImpl.java:102)
com.sneaker.daoimpl.CustomerDaoImpl.login(CustomerDaoImpl.java:29)
com.sneaker.service.CustomerService.login(CustomerService.java:20)
com.sneaker.action.CustomerAction.login(CustomerAction.java:42)
...

9个回答

看看你的sql语法是否正确或者是映射文件对不对

查询出错,把查询sql,还有CustomerDaoImpl.login(),发出来(ps这种错误要不是sql写错了,就是方法写错了)

这张表跟实体类对应吗,字段个数,名称大小写,类型。

xionglangs
编程爱好者熊浪 org.hibernate.type.IntegerType.get(IntegerType.java:51),oracle.jdbc.driver.NumberCommonAccessor.getInt(NumberCommonAccessor.java:103)似乎说你的数字溢出了。
接近 3 年之前 回复

hql,参数贴出来
驱动jar文件的图

这是Hibernate入门的一个代码,有一个小案例,你下下来运行下,对照的看看你的驱动和配置文件有没有问题。http://blog.csdn.net/tiandixuanwuliang/article/details/56917780

public boolean login(Customer c) {
    boolean ispass=false;
    Session session=sessionFactory.getCurrentSession();
    session.beginTransaction();
    String hql="from Customer c where c.c_name=?";
    Query query= session.createQuery(hql);
    query.setString(0, c.getC_name());
    System.out.println(query.list().equals(null));
    Customer cget=(Customer)query.uniqueResult();
    String pd=cget.getC_password(); 
    if(c.getC_password()==pd){
        ispass=true;
    }
    session.getTransaction().commit();
    session.close();
    return ispass;
}
实现类是这样的

<?xml version="1.0" encoding="UTF-8"?>
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-2.5.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">

<context:annotation-config />
<context:component-scan base-package="com.sneaker.*" />
<!--<tx:annotation-driven transaction-manager="txManager"/>-->


<bean id="customerdaoimp" class="com.sneaker.daoimpl.CustomerDaoImpl">
    <property name="sessionFactory" ref="sessionFactory"></property>
</bean>

<bean id="customerservice" class="com.sneaker.service.CustomerService">
    <property name="cusdao" ref="customerdaoimp" />
</bean>

<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
    destroy-method="close">
    <property name="driverClassName" value="oracle.jdbc.driver.OracleDriver" />
    <property name="url" value="jdbc:oracle:thin:@localhost:1521:orcl" />
    <property name="username" value="sneaker" />
    <property name="password" value="caifeng"/>
</bean>

<bean id="sessionFactory"
    class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
    <property name="dataSource" ref="dataSource" />
    <property name="packagesToScan">
        <list>
            <value>com.sneaker.model.*</value>
        </list>
    </property>
    <property name="hibernateProperties">
        <props>
            <prop key="hibernate.dialect">org.hibernate.dialect.Oracle10gDialect</prop>
            <prop key="hibernate.show_sql">true</prop>
            <prop key="hibernate.hbm2ddl.auto">update</prop>
            <prop key="hibernate.current_session_context_class">thread</prop>
        </props>
    </property>
</bean>


这是我的配置文件,使用的注解配置的

create table Customer (
C_ID number PRIMARY KEY,
c_Name varchar2(30) UNIQUE NOT NULL, --用户名
c_level varchar2(30) not null,--用户等级
c_password varchar2(30) not null,--密码
c_tel number,--电话
c_email varchar2(30),--电子邮箱
C_Address varchar2(50) --收货地址

) 这是建表语句
对应的实体类
package com.sneaker.model;

import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Entity;
import javax.persistence.Table;

@Entity
@Table(name="Customer")
public class Customer {

private int c_id;
private String c_name ; 
private String c_level;
private String c_password;
private int c_tel;
private String c_email;
private String c_address;

@Id
public int getC_id() {
    return c_id;
}
public void setC_id(int c_id) {
    this.c_id = c_id;
}
public String getC_name() {
    return c_name;
}
public void setC_name(String c_name) {
    this.c_name = c_name;
}
public String getC_level() {
    return c_level;
}
public void setC_level(String c_level) {
    this.c_level = c_level;
}
public String getC_password() {
    return c_password;
}
public void setC_password(String c_password) {
    this.c_password = c_password;
}
public int getC_tel() {
    return c_tel;
}
public void setC_tel(int c_tel) {
    this.c_tel = c_tel;
}
public String getC_email() {
    return c_email;
}
public void setC_email(String c_email) {
    this.c_email = c_email;
}
public String getC_address() {
    return c_address;
}
public void setC_address(String c_address) {
    this.c_address = c_address;
}

}

class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">改成org.springframework.orm.hibernate4.LocalSessionFactoryBean试试呢

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问