2 qq 29052403 qq_29052403 于 2016.01.27 20:37 提问

求高手帮助我,急!如下所示!

我的oracle版本号如图:
图片说明
myeclipse2014,hibernate jar包图片说明
hibernate configure
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">

<session-factory>
    <property name="connection.username">scott</property>
    <property name="connection.url">jdbc:oracle:thin:@localhost:1521:orcl</property>
    <property name="dialect">org.hibernate.dialect.Oracle9Dialect</property>
    <property name="myeclipse.connection.profile">oracle</property>
    <property name="connection.password">123123</property>
    <property name="connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
    <property name="show_sql">true</property>

    <!-- <mapping resource="entity/User.hbm.xml"/>  -->
    <mapping resource="entity/Abc.hbm.xml"/>

</session-factory>


实体
package entity;

import java.io.Serializable;
import java.util.List;

public class Abc{
private int id;
private String uname;
private int age;
private char sex;
private String password;
private String headimg;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getUname() {
return uname;
}
public void setUname(String uname) {
this.uname = uname;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getHeadimg() {
return headimg;
}
public void setHeadimg(String headimg) {
this.headimg = headimg;
}

public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public char getSex() {
return sex;
}
public void setSex(char sex) {
this.sex = sex;
}
public Abc() {
super();
}
}
映射
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >

<class name="entity.User" table="t_user">
    <id name="id" column="u_id">
        <generator class="sequence">
            <param name="sequence">SQL_MARY</param>
        </generator>
    </id>
    <property name="uname" column="u_name" type="java.lang.String" />
    <property name="age" column="u_age" />
    <property name="sex" column="u_sex" />
    <property name="password" column="u_password" />
    <property name="headimg" column="head" />
</class>


测试类
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;

import entity.Abc;

public class test {
public static void main(String args[])
{
Configuration cfg=new Configuration();
cfg.configure();
SessionFactory sf=cfg.buildSessionFactory();
Session s=sf.openSession();
Abc a=new Abc();
a.setUname("xxk");
a.setAge(21);
a.setHeadimg("1.jpg");
a.setPassword("1213564");
a.setSex('男');
try
{
s.getTransaction().begin();
s.save(a);
s.getTransaction().commit();
}catch(Exception e)
{
e.printStackTrace();
s.getTransaction().rollback();
}
if(s!=null)
{
s.close();
}
}
}
异常
图片说明
一月 27, 2016 8:04:59 下午 org.hibernate.annotations.common.reflection.java.JavaReflectionManager
INFO: HCANN000001: Hibernate Commons Annotations {4.0.4.Final}
一月 27, 2016 8:04:59 下午 org.hibernate.Version logVersion
INFO: HHH000412: Hibernate Core {4.3.1.Final}
一月 27, 2016 8:04:59 下午 org.hibernate.cfg.Environment
INFO: HHH000206: hibernate.properties not found
一月 27, 2016 8:04:59 下午 org.hibernate.cfg.Environment buildBytecodeProvider
INFO: HHH000021: Bytecode provider name : javassist
一月 27, 2016 8:04:59 下午 org.hibernate.cfg.Configuration configure
INFO: HHH000043: Configuring from resource: /hibernate.cfg.xml
一月 27, 2016 8:04:59 下午 org.hibernate.cfg.Configuration getConfigurationInputStream
INFO: HHH000040: Configuration resource: /hibernate.cfg.xml
一月 27, 2016 8:04:59 下午 org.hibernate.internal.util.xml.DTDEntityResolver resolveEntity
WARN: HHH000223: Recognized obsolete hibernate namespace http://hibernate.sourceforge.net/. Use namespace http://www.hibernate.org/dtd/ instead. Refer to Hibernate 3.6 Migration Guide!
一月 27, 2016 8:04:59 下午 org.hibernate.cfg.Configuration addResource
INFO: HHH000221: Reading mappings from resource: entity/Abc.hbm.xml
一月 27, 2016 8:04:59 下午 org.hibernate.internal.util.xml.DTDEntityResolver resolveEntity
WARN: HHH000223: Recognized obsolete hibernate namespace http://hibernate.sourceforge.net/. Use namespace http://www.hibernate.org/dtd/ instead. Refer to Hibernate 3.6 Migration Guide!
一月 27, 2016 8:04:59 下午 org.hibernate.cfg.Configuration doConfigure
INFO: HHH000041: Configured SessionFactory: null
一月 27, 2016 8:05:00 下午 org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
WARN: HHH000402: Using Hibernate built-in connection pool (not for production use!)
一月 27, 2016 8:05:00 下午 org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
INFO: HHH000401: using driver [oracle.jdbc.driver.OracleDriver] at URL [jdbc:oracle:thin:@localhost:1521:orcl]
一月 27, 2016 8:05:00 下午 org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
INFO: HHH000046: Connection properties: {user=scott, password=****}
一月 27, 2016 8:05:00 下午 org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
INFO: HHH000006: Autocommit mode: false
一月 27, 2016 8:05:00 下午 org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
INFO: HHH000115: Hibernate connection pool size: 20 (min=1)
Exception in thread "main" org.hibernate.exception.JDBCConnectionException: Error calling Driver#connect
at org.hibernate.engine.jdbc.connections.internal.BasicConnectionCreator$1$1.convert(BasicConnectionCreator.java:122)
at org.hibernate.engine.jdbc.connections.internal.BasicConnectionCreator.convertSqlException(BasicConnectionCreator.java:140)
at org.hibernate.engine.jdbc.connections.internal.DriverConnectionCreator.makeConnection(DriverConnectionCreator.java:58)
at org.hibernate.engine.jdbc.connections.internal.BasicConnectionCreator.createConnection(BasicConnectionCreator.java:75)
at org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl.configure(DriverManagerConnectionProviderImpl.java:106)
at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:89)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:206)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:178)
at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.buildJdbcConnectionAccess(JdbcServicesImpl.java:260)
at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.configure(JdbcServicesImpl.java:94)
at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:89)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:206)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:178)
at org.hibernate.cfg.Configuration.buildTypeRegistrations(Configuration.java:1885)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1843)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1928)
at test.main(test.java:13)
Caused by: java.sql.SQLException: Io 异常: The Network Adapter could not establish the connection
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:112)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:146)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:255)
at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:387)
at oracle.jdbc.driver.PhysicalConnection.(PhysicalConnection.java:439)
at oracle.jdbc.driver.T4CConnection.(T4CConnection.java:165)
at oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:35)
at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:801)
at org.hibernate.engine.jdbc.connections.internal.DriverConnectionCreator.makeConnection(DriverConnectionCreator.java:55)
... 14 more

5个回答

caozhy
caozhy   Ds   Rxr 2016.01.27 21:09

别的也不用贴了,错误信息很清楚,jdbc驱动问题,检查你的驱动jar包和连接字符串,以及你的数据库服务器的配置。

enpterexpress
enpterexpress   2016.01.27 22:00
qq_34810008
qq_34810008   2016.04.27 14:17

数据库配置信息是orcl吗 看是否与数据库匹配

qq_34810008
qq_34810008   2016.04.27 14:17

数据库配置信息是orcl吗 看是否与数据库匹配

qq_29052403
qq_29052403   2016.01.27 20:38

我的电脑是64位,oracle是32,PLSQL是32

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!