简体   繁体   English

空ResultSet以及如何填充它

[英]Null ResultSet and how to fill it

I have the next code: 我有下一个代码:

ResultSet rs= null; 
TipoEstablecimientoHotel tipoEstablecimiento = new TipoEstablecimientoHotel(rs);

Of course, the second line goes into a null pointer exception, so I want to initialize tha "rs", but I don't want the data coming from a database at this point. 当然,第二行进入了空指针异常,因此我想初始化“ rs”,但是我现在不希望数据来自数据库。 I'm lost with it. 我迷路了。

We have no idea what TipoEstablecimientoHotel does, or why it needs a result set. 我们不知道TipoEstablecimientoHotel做什么,或者为什么它需要结果集。 If it needs it at the point of construction then either you need to defer constructing TipoEstablecimientoHotel until you've got the results, or you need to redesign it so you can give it the data later. 如果需要它在施工点则要么需要推迟建设TipoEstablecimientoHotel ,直到你的结果, 或者你需要重新设计,以便可以以后给它的数据。

Basically, a problem like this should be taken as a suggestion to take a step back and consider your design - think about what should need data when, and adjust the design to meet those needs. 基本上,这样的问题应该被视为一个建议,退后一步,并考虑您的设计-想想应该需要时数据,并调整设计,以满足这些需求。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM