Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/359.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
尝试在Java方法中实现SQLGrammarException_Java_Hibernate - Fatal编程技术网

尝试在Java方法中实现SQLGrammarException

尝试在Java方法中实现SQLGrammarException,java,hibernate,Java,Hibernate,我试图在我的方法中实现SQLGrammarException。 此方法显示列错误,但我需要显示包含错误的列来自哪个过程 public static PersistenceMicrodataException dealHibernateException(Throwable e) { e.printStackTrace(); Throwable t = ExceptionUtil.getCause(e); return new PersistenceMicrodat

我试图在我的方法中实现SQLGrammarException。 此方法显示列错误,但我需要显示包含错误的列来自哪个过程

    public static PersistenceMicrodataException dealHibernateException(Throwable e) {
    e.printStackTrace();
    Throwable t = ExceptionUtil.getCause(e);
    return new PersistenceMicrodataException(t.getMessage(), t);
 }
我试试这个:

public static PersistenceMicrodataException dealHibernateException(Throwable e) {
    try {
        Throwable t = ExceptionUtil.getCause(e);
    } catch (Exception e) {
        System.out.println(t.getMessage());
        System.out.println(((SQLGrammarException) t).getSQLState());
        System.out.println(((SQLGrammarException) t).getErrorCode());
        System.out.println(t.getCause());
    }
    return new PersistenceMicrodataException(e.getMessage(), e);
}
有人能帮我吗?

我找到了解决办法

public static PersistenceMicrodataException dealHibernateException(Throwable e) {
    String concatError = ((SQLGrammarException) e).getSQL() + ((SQLGrammarException) e).getClass() + ((SQLGrammarException) e).getCause();
    while (e != null) {
        java.lang.System.out.println(concatError);
        break;
    }           
    Throwable t = ExceptionUtil.getCause(e);
    return new PersistenceMicrodataException(concatError,t);
}
我找到了解决办法

public static PersistenceMicrodataException dealHibernateException(Throwable e) {
    String concatError = ((SQLGrammarException) e).getSQL() + ((SQLGrammarException) e).getClass() + ((SQLGrammarException) e).getCause();
    while (e != null) {
        java.lang.System.out.println(concatError);
        break;
    }           
    Throwable t = ExceptionUtil.getCause(e);
    return new PersistenceMicrodataException(concatError,t);
}