A ResultSet
提供getInt()
返回原语的方法int
.是否有可能获得Integer
允许的物体null
?我正在检索的DB字段是可空的,只要字段是,getInt()
我0
就会返回null
.
谢谢
我有一个hashmap:
Map<LotWaferBean, File> hm = new HashMap<LotWaferBean, File>();
LotWaferBean lw = new LotWaferBean();
... //populate lw
if (!hm.containsKey((LotWaferBean) lw)) {
hm.put(lw, triggerFiles[l]);
}
Run Code Online (Sandbox Code Playgroud)
代码LotWaferBean
:
@Override
public boolean equals(Object o) {
if (!(o instanceof LotWaferBean)) {
return false;
}
if (((LotWaferBean) o).getLotId().equals(lotId)
&& ((LotWaferBean) o).getWaferNo() == waferNo) {
return true;
}
return false;
}
Run Code Online (Sandbox Code Playgroud)
在我的IDE中,我将断点放入,equals()
但它永远不会被执行.为什么?
我在Tomcat中托管了一个3层appln; 网络,服务和DAO层.
你如何整合Tomcat和Spring?我需要利用Spring的依赖注入,事务管理等.
我只能想到实例化一个ClassPathXmlApplicationContext,但这样,ApplicationContext单例实例在各层之间是不可见的.
提前致谢.
最好的祝福
将
我正在使用嵌入在Tomcat 5.5.26中的OpenEJB 3.1.3,我使用hibernate 3.6作为JPA提供程序.
这是我的persistence.xml:
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="1.0"
xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">
<persistence-unit name="manager1" transaction-type="JTA">
<!-- provider is optional if you work with only 1 JPA provider -->
<!--
<provider>org.hibernate.ejb.HibernatePersistence</provider>
-->
<jta-data-source>java:/DefaultDS</jta-data-source>
<!--
<properties>
<property name="hibernate.ejb.cfgfile" value="/hibernate.cfg.xml" />
</properties>
-->
</persistence-unit>
</persistence>
Run Code Online (Sandbox Code Playgroud)
这是我的代码:
@Stateless
public class MapSearchManager implements MapSearchLocal, MapSearchRemote {
@PersistenceContext
private EntityManager em;
...
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public int queryDataSelectionNumRecords(MapSearchParamBean paramBean) {
Criteria c = createCriteria(paramBean);
c.setProjection(Projections.rowCount());
List l = c.list();
...
}
...
}
Run Code Online (Sandbox Code Playgroud)
当我使用OpenEJB运行tomcat并且我的app war存档时,部署失败,异常堆栈跟踪:
2010-10-27 …
Run Code Online (Sandbox Code Playgroud) 我使用Spring SimpleJDBCTemplate
来访问Oracle DB.这是我的代码.
String sql = "SELECT from_bin_code FROM hbin_import_mapping";
return jt.query(sql, new BeanHbinImportMappingMapper(), (Object) null);
Run Code Online (Sandbox Code Playgroud)
行映射器是:
public class BeanHbinImportMappingMapper
implements
RowMapper<BeanHbinImportMapping> {
public BeanHbinImportMapping mapRow(ResultSet rs, int rowno)
throws SQLException {
int fromBinCode = rs.getInt("from_bin_code");
// char fromBinCodeChar = rs.getString("from_bin_code_char").charAt(0);
// boolean fromBinCodeAllowed = rs.getString("from_bin_code_allowed")
// .equals("Y") ? true : false;
// int oliBinCode = rs.getInt("oli_bin_code");
// String oliBinQuality = rs.getString("oli_bin_quality");
// String oliBinGroup = rs.getString("oli_bin_group");
// String oliBinDesc = rs.getString("oli_bin_desc");
// boolean olibinRef = rs.getString("oli_bin_ref").equals("Y") ? true …
Run Code Online (Sandbox Code Playgroud) 我使用JAXB 2来解析XSD架构的XML文件,并在ants构建到Java类期间自动解组XML标签.有些enums
是创造的.代码是:
@XmlType(name = "binQuality")
@XmlEnum
public enum BinQuality {
GOOD,
BAD,
UGLY,
NULL;
public String value() {
return name();
}
public static BinQuality fromValue(String v) {
return valueOf(v);
}
}
Run Code Online (Sandbox Code Playgroud)
在我的代码中我打电话:
BinQuality bq = BinQuality.valueOf(him.getToBinQuality());
Run Code Online (Sandbox Code Playgroud)
在一个循环中,我只在第91次迭代中获得异常.
*******更新*******
him.getToBinQuality()
确实返回有效的枚举(GOOD/BAD/UGLY/NULL).以下是日志的摘录.
....
2011-07-18 15:28:09 DEBUG (com.st.mas.wmr.persistence.process.ProcessStifOliBinConversionCompleteImpl:183) -> class com.st.mas.wmr.persistence.process.ProcessStifOliBinConversionCompleteImpl|exportToXml|him.getToBin():89|him.getToBinQuality():BAD
2011-07-18 15:28:09 DEBUG (com.st.mas.wmr.persistence.process.ProcessStifOliBinConversionCompleteImpl:183) -> class com.st.mas.wmr.persistence.process.ProcessStifOliBinConversionCompleteImpl|exportToXml|him.getToBin():90|him.getToBinQuality():UGLY
2011-07-18 15:28:09 DEBUG (com.st.mas.wmr.persistence.process.ProcessStifOliBinConversionCompleteImpl:183) -> class com.st.mas.wmr.persistence.process.ProcessStifOliBinConversionCompleteImpl|exportToXml|him.getToBin():91|him.getToBinQuality():BAD
2011-07-18 15:28:09 WARN (org.apache.struts.action.RequestProcessor:538) -> Unhandled …
Run Code Online (Sandbox Code Playgroud) java ×4
spring ×2
containskey ×1
enums ×1
equals ×1
hashmap ×1
hibernate ×1
jaxb ×1
jdbc ×1
jdbctemplate ×1
jpa ×1
openejb ×1
sqlexception ×1
tomcat ×1