org.hibernate.exception.GenericJDBCException: 无法执行查询,尽管能够从SQL获取结果

huangapple 未分类评论48阅读模式
英文:

org.hibernate.exception.GenericJDBCException: could not execute query though able to get result from sql

问题

我正在尝试执行一个 Hibernate 查询

    final StringBuilder sql = new StringBuilder(50);
    sql.append("SELECT DISTINCT  SN.GTIN || ',' || SN.BATCH_NBR||','||SN.EXPIRATION_DATE||','||SN.SRL_NBR  from C_SRL_NBR SN");
    sql.append(" WHERE TC_LPN_ID =:cartonNum");

    final String[] nameList = { "cartonNum" };
	final Object[] parmList = { cartonNum };

	List<String> columnName = new ArrayList<>();
	List<Type> columnType = new ArrayList<>();

	columnName.add("GTIN");
	columnName.add("BATCH_NBR");
	columnName.add("EXPIRATION_DATE");
	columnName.add("SRL_NBR");
	columnType.add(Type.STRING);
	columnType.add(Type.STRING);
	columnType.add(Type.STRING);
	columnType.add(Type.STRING);

	try {
		@SuppressWarnings("unchecked")
		final List<String> list = directSQLQuery(sql.toString(), nameList, parmList, columnName, columnType);
		if (list != null && !list.isEmpty()) {
			return list;
		}
	} catch (Exception e)
		throw new DataAccessException(e);
	}

当我在数据库中运行查询时,可以得到输出,但通过代码运行时会出现异常,请问有谁可以帮忙解决这个问题。

英文:

I am trying to excute a hibernate query

    final StringBuilder sql = new StringBuilder(50);
    sql.append(&quot;SELECT DISTINCT  SN.GTIN || &#39;,&#39; || SN.BATCH_NBR||&#39;,&#39;||SN.EXPIRATION_DATE||&#39;,&#39;||SN.SRL_NBR  from C_SRL_NBR SN&quot;);
    sql.append(&quot; WHERE TC_LPN_ID =:cartonNum&quot;);

    final String[] nameList = { &quot;cartonNum&quot; };
	final Object[] parmList = { cartonNum };

	List&lt;String&gt; columnName = new ArrayList&lt;&gt;();
	List&lt;Type&gt; columnType = new ArrayList&lt;&gt;();

	columnName.add(&quot;GTIN&quot;);
	columnName.add(&quot;BATCH_NBR&quot;);
	columnName.add(&quot;EXPIRATION_DATE&quot;);
	columnName.add(&quot;SRL_NBR&quot;);
	columnType.add(Type.STRING);
	columnType.add(Type.STRING);
	columnType.add(Type.STRING);
	columnType.add(Type.STRING);

	try {
		@SuppressWarnings(&quot;unchecked&quot;)
		final List&lt;String&gt; list = directSQLQuery(sql.toString(), nameList, parmList, columnName, columnType);
		if (list != null &amp;&amp; !list.isEmpty()) {
			return list;
		}
	} catch (Exception e)
		throw new DataAccessException(e);
	}

when I am running the query in db it is giving me output but through code it is giving exception can any one please help with this

huangapple
  • 本文由 发表于 2020年5月5日 01:02:12
  • 转载请务必保留本文链接:https://java.coder-hub.com/61597649.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定