Hibernate3.2是否和MYSQL5.1不兼容兼容

解决方案 »

  1.   

    把MYSQL换成5.0的,
    我要一百分.
      

  2.   

    我只调用了一个SAVE()
    下面有个例子 你们看1下 ,它就插入了1行,结果返回7810893而不是 J2EE说的-2(唯一正确值),并且返回7810893的同时,可以插入到数据库中package jdb;import java.io.BufferedInputStream;
    import java.io.FileInputStream;
    import java.io.IOException;
    import java.io.InputStream;
    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.SQLException;
    import java.sql.Statement;
    import java.util.Properties;public class TestBatch {
    public static Connection getConnection() throws SQLException,IOException, ClassNotFoundException {
    Class.forName("com.mysql.jdbc.Driver");
    Properties props = new Properties();
    InputStream in = new BufferedInputStream(new FileInputStream("config.property"));
    props.load(in);
    in.close();

    return DriverManager.getConnection(props.getProperty("url"), 
    props.getProperty("user"),
    props.getProperty("password"));


    }

    public static Statement getState(Connection con) throws SQLException, IOException, ClassNotFoundException{
    return con.createStatement();

    }

    public static Statement addBatch(Statement state, String[] sql) throws SQLException, IOException, ClassNotFoundException {

    if (sql.length <1){
    System.out.println("no sql batch");

    }
    else{
    //System.out.println(sql.length);
    for (int i=0;i<sql.length;i++){
    state.addBatch(sql[i]);

    }
    return state;
    }
    return null;

    }

    public static void close(Connection state) throws SQLException {
    state.close();
    }
    public static void main(String[] args)  {
    String[] sql = {"insert into events values(3,'2007-01-06','qiuting')"};
    try{
    Connection con = TestBatch.getConnection();
    Statement stat = TestBatch.getState(con); 
    TestBatch.addBatch(stat, sql);
    int[] res = stat.executeBatch();
    TestBatch.close(con);
    for (int i=0; i<res.length; i++){
    System.out.println("return values "+res[i]);
    }

    System.out.println("ok");
    }catch(Exception e){
    System.err.println(e);

    }
    finally{

    }


    }
      

  3.   

    跟hibernate完全无关,似乎是mysql驱动和数据库版本对不上的原因,你换成mysql5.0应该就没问题了
      

  4.   

    我这几天也遇到这个问题,因为我用的数据库是MySql 版本是Ver 14.13 Distrib 5.1.20-beta, for Win32 (ia32),当时的驱动是5.0.5 当换了数据库更换到5.0时,没有问题。感觉的确是驱动的问题。但是我把驱动换到5.1.6(数据库版本5.1)时仍然出现会楼主遇到的问题。
    要是驱动的问题,那5.1应该使用哪个版本的驱动呢?
      

  5.   

    对阿,我现在是mysql5.1,需要采用什么用的版本呢