gpt4 book ai didi

java - 我们什么时候在 SQLException 中得到 "' NaN' is not a valid numeric or approximation numeric value”?

转载 作者:行者123 更新时间:2023-11-30 01:33:56 28 4
gpt4 key购买 nike

我在 JSP 中添加了以下代码,并在将实体保存到数据库时出现一些异常。

 $('.validateWeight').click(function(event) {
var id = event.target.id;
var value;
$("#saveValue").val("");
if(id == "saveAndContinue"){
var el = document.getElementById('saveValue');
el.value = 1;
//<c:set var="saveValue" scope="page" value="1"/>;
}else if(id=="saveAndClose"){
var el = document.getElementById('saveValue');
el.value = 2;
//<c:set var="saveValue" scope="page" value="2"/>;
}

在我的Java Action Class中,我添加了 getter 和 setter

在需要的情况下,我将值设置为 1 和 2,但是在保存实体时,我不知道“NAN”值是如何以及从哪里来的,并且我遇到了保存调用的问题。

异常:

org.springframework.dao.TransientDataAccessResourceException: Hibernate operation: could not update: [com.hk.domain.inventory.GrnLineItem#100]; SQL [update person set age=?, no_of_children=?, address_line_1=?, address_line_2=?, mrp=?, state=?, city=?, pincode=?, weight=? where id=?]; 'NaN' is not a valid numeric or approximate numeric value; nested exception is java.sql.SQLException: 'NaN' is not a valid numeric or approximate numeric value
org.springframework.jdbc.support.SQLStateSQLExceptionTranslator.doTranslate(SQLStateSQLExceptionTranslator.java:107)
org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:72)
org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:80)
org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:80)
org.springframework.orm.hibernate3.HibernateAccessor.convertJdbcAccessException(HibernateAccessor.java:424)
org.springframework.orm.hibernate3.HibernateAccessor.convertHibernateAccessException(HibernateAccessor.java:410)
org.springframework.orm.hibernate3.HibernateTemplate.doExecute(HibernateTemplate.java:411)
org.springframework.orm.hibernate3.HibernateTemplate.executeWithNativeSession(HibernateTemplate.java:374)
org.springframework.orm.hibernate3.HibernateTemplate.flush(HibernateTemplate.java:881)
com.hk.impl.dao.BaseDaoImpl.resetHibernateAfterWrite(BaseDaoImpl.java:247)

java.sql.SQLException: 'NaN' is not a valid numeric or approximate numeric value
com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1055)
com.mysql.jdbc.SQLError.createSQLException(SQLError.java:956)
com.mysql.jdbc.SQLError.createSQLException(SQLError.java:926)
com.mysql.jdbc.PreparedStatement.setDouble(PreparedStatement.java:3572)
org.apache.commons.dbcp.DelegatingPreparedStatement.setDouble(DelegatingPreparedStatement.java:129)
org.apache.commons.dbcp.DelegatingPreparedStatement.setDouble(DelegatingPreparedStatement.java:129)
org.apache.commons.dbcp.DelegatingPreparedStatement.setDouble(DelegatingPreparedStatement.java:129)
org.hibernate.type.DoubleType.set(DoubleType.java:60)
org.hibernate.type.NullableType.nullSafeSet(NullableType.java:154)
org.hibernate.type.NullableType.nullSafeSet(NullableType.java:131)
org.hibernate.persister.entity.AbstractEntityPersister.dehydrate(AbstractEntityPersister.java:2025)
org.hibernate.persister.entity.AbstractEntityPersister.update(AbstractEntityPersister.java:2399)
org.hibernate.persister.entity.AbstractEntityPersister.updateOrInsert(AbstractEntityPersister.java:2335)
org.hibernate.persister.entity.AbstractEntityPersister.update(AbstractEntityPersister.java:2635)
org.hibernate.action.EntityUpdateAction.execute(EntityUpdateAction.java:115)
org.hibernate.engine.ActionQueue.execute(ActionQueue.java:279)
org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:263)
org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:168)
org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:321)
org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:50)
org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1027)
org.springframework.orm.hibernate3.HibernateTemplate$28.doInHibernate(HibernateTemplate.java:883)
org.springframework.orm.hibernate3.HibernateTemplate.doExecute(HibernateTemplate.java:406)
org.springframework.orm.hibernate3.HibernateTemplate.executeWithNativeSession(HibernateTemplate.java:374)
org.springframework.orm.hibernate3.HibernateTemplate.flush(HibernateTemplate.java:881)
com.hk.impl.dao.BaseDaoImpl.resetHibernateAfterWrite(BaseDaoImpl.java:247)
com.hk.impl.dao.BaseDaoImpl.save(BaseDaoImpl.java:237)

最佳答案

您可以修改 JavaScript 以使用 Jquery

$('.validateWeight').click(function(event) {
var id = event.target.id;

$("#saveValue").val("");
if (id == "saveAndContinue")
$("#saveValue").val(1);
else if (id == "saveAndClose")
$("#saveValue").val(2);
}

您必须考虑到,如果 id 不是“saveAndContinue”或“saveAndClose”,则 ID 为“saveValue”的输入值将为“”,它不是数字,并且将产生 NaN 错误。

另一方面,您应该检查在服务器端是否收到字符串或整数,因为您应该向 Hibernate 函数传递一个整数。

关于java - 我们什么时候在 SQLException 中得到 "' NaN' is not a valid numeric or approximation numeric value”?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17143715/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com