qq_40876271
ape_Ceasar
2017-12-12 14:10

JDBC version [3] less than 4的异常

5
  • jdbc的相关文件
  • hibernate

报错在这里
INFO: HHH000423: Disabling contextual LOB creation as JDBC driver reported JDBC version [3] less than 4
Exception in thread "main" java.lang.NullPointerException
at hibernateJava_1.Test.test(Test.java:30)
at hibernateJava_1.Test.main(Test.java:39)

代码是这个
package hibernateJava_1;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;

public class Test {

public static void test(){
    //价值hibernate核心配置文件
    Configuration cfg=new Configuration();
    cfg.configure();
    //创建session工厂对象
    SessionFactory factory=null;
    Session session=null;
    Transaction tx=null;
    try{
        factory=cfg.buildSessionFactory();
        //创建session
        session=factory.openSession();
        //开始实务
         tx=session.beginTransaction();
        //crud

        session.save(new User(1,"zhangSan",23,"captain"));
        //结束事务
        tx.commit();
    }catch(Exception e){
        tx.rollback();
        e.printStackTrace();
    }finally{
        if(session!=null)session.close();
        if(factory!=null)factory.close();

    }
}
public static void main(String[] args) {
    test();
}

}

这里是映射xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">









这里是核心hibernate.fig.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">


<!-- 四大参数 -->
com.mysql.jdbc.Driver
jdbc:mysql:///student
root
123

<!-- 在控制台显示sql -->
true
true
<!-- 自动建表 -->
update
<!-- 识别方言 -->
org.hibernate.dialect.MySQLDialect
<!-- 映射那个user映射xml文件 -->



映射实体类应该也没有什么错啊
package hibernateJava_1;

public class User {
private int uid;
private String username;
private int age;
private String address;

  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

5条回答

为你推荐