Я использую базу данных оракула и весеннюю ибатису.Как выбрать строку с столбцом с минимальным значением
У меня есть запрос, который вернет два результата из того, что мне нужно получить запись, которая имеет минимальное значение для столбца.
В Oracle я сделать это, используя ниже запроса:
SELECT *
FROM ANUMBER$ROOT ROOT
WHERE ROOT.ROOT_NUMBER=1546305
AND ROOT.MOL_WEIGHT = (SELECT MIN(MOL_WEIGHT)
FROM ANUMBER$ROOT
WHERE ROOT_NUMBER=1546305);
Я преобразовал этот запрос, как показано ниже в весеннем Ibatis
SELECT *
FROM ANUMBER$ROOT ROOT
WHEREe ROOT.ROOT_NUMBER= #value#
AND ROOT.MOL_WEIGHT = (SELECT MIN(MOL_WEIGHT)
FROM ANUMBER$ROOT
WHERE ROOT_NUMBER= #value#);
Но это бросает меня под ошибкой:
**log4j:WARN No appenders could be found for logger (org.springframework.context.support.ClassPathXmlApplicationContext). log4j:WARN Please initialize the log4j system properly. Exception in thread "main" org.springframework.jdbc.UncategorizedSQLException: SqlMapClient operation; uncategorized SQLException for SQL []; SQL state [null]; error code [0];
--- The error occurred in abbott/gprd/compoundInfo/dao/ibatis/LibraCompoundInformationLookup.xml.--- The error occurred while preparing the mapped statement for execution.
--- Check the selectCompoundInfoByRootNumber.
--- Check the SQL statement.
--- Cause: java.util.NoSuchElementException; nested exception is com.ibatis.common.jdbc.exception.NestedSQLException:
--- The error occurred in abbott/gprd/compoundInfo/dao/ibatis/LibraCompoundInformationLookup.xml.--- The error occurred while preparing the mapped statement for execution.
--- Check the selectCompoundInfoByRootNumber.
--- Check the SQL statement.
--- Cause: java.util.NoSuchElementException Caused by: com.ibatis.common.jdbc.exception.NestedSQLException:
--- The error occurred in abbott/gprd/compoundInfo/dao/ibatis/LibraCompoundInformationLookup.xml.--- The error occurred while preparing the mapped statement for execution.
--- Check the selectCompoundInfoByRootNumber.
--- Check the SQL statement.
--- Cause: java.util.NoSuchElementException at com.ibatis.sqlmap.engine.mapping.statement.GeneralStatement.executeQueryWithCallback(GeneralStatement.java:188) at com.ibatis.sqlmap.engine.mapping.statement.GeneralStatement.executeQueryForObject(GeneralStatement.java:104) at com.ibatis.sqlmap.engine.impl.SqlMapExecutorDelegate.queryForObject(SqlMapExecutorDelegate.java:566) at com.ibatis.sqlmap.engine.impl.SqlMapExecutorDelegate.queryForObject(SqlMapExecutorDelegate.java:541) at com.ibatis.sqlmap.engine.impl.SqlMapSessionImpl.queryForObject(SqlMapSessionImpl.java:106) at org.springframework.orm.ibatis.SqlMapClientTemplate$1.doInSqlMapClient(SqlMapClientTemplate.java:243) at org.springframework.orm.ibatis.SqlMapClientTemplate.execute(SqlMapClientTemplate.java:193) at org.springframework.orm.ibatis.SqlMapClientTemplate.queryForObject(SqlMapClientTemplate.java:241) at abbott.gprd.compoundInfo.dao.ibatis.CompoundInformationDao.getCompoundInformationForRootNumber(CompoundInformationDao.java:66) at abbott.gprd.compoundInfo.dao.ibatis.CompoundInformationDao.main(CompoundInformationDao.java:183) Caused by: java.util.NoSuchElementException at java.util.StringTokenizer.nextToken(StringTokenizer.java:332) at com.ibatis.sqlmap.engine.mapping.sql.simple.SimpleDynamicSql.processDynamicElements(SimpleDynamicSql.java:90) at com.ibatis.sqlmap.engine.mapping.sql.simple.SimpleDynamicSql.getSql(SimpleDynamicSql.java:45) at com.ibatis.sqlmap.engine.mapping.statement.GeneralStatement.executeQueryWithCallback(GeneralStatement.java:168) ... 9 more ERROR: JDWP Unable to get JNI 1.2 environment, jvm->GetEnv() return code = -2 JDWP exit error AGENT_ERROR_NO_JNI_ENV(183): [../../../src/share/back/util.c:820]**
Может ли кто-нибудь помочь мне в преобразовании этого запроса из oracle в spring ibatis?
Я бы поменял # значение # на 1546305 и попробовал, если он будет работать. – Egl
Это не помогает – Prakash