null

How do I in JDBC read a possibly null double value from resultSet?

我的未来我决定 提交于 2019-12-28 05:56:37
问题 I have a column in my database that is typed double and I want to read the value from it using a JDBC ResultSet, but it may be null. What is the best way of doing this? I can think of three options none of which seem very good. Option 1: Bad because exception handling verbose and smelly double d; try { d = rs.getDouble(1); // do something } catch(SQLException ex) { if(rs.wasNull()) { // do something else } else { throw ex; } } Option 2: Bad because two fetches s = rs.getString(1); // or

Filter values only if not null using lambda in Java8

断了今生、忘了曾经 提交于 2019-12-28 03:21:25
问题 I have a list of objects say car . I want to filter this list based on some parameter using Java 8. But if the parameter is null , it throws NullPointerException . How to filter out null values? Current code is as follows requiredCars = cars.stream().filter(c -> c.getName().startsWith("M")); This throws NullPointerException if getName() returns null . 回答1: In this particular example I think @Tagir is 100% correct get it into one filter and do the two checks. I wouldn't use Optional.ofNullable

IN Clause with NULL or IS NULL

淺唱寂寞╮ 提交于 2019-12-28 01:53:04
问题 Postgres is the database Can I use a NULL value for a IN clause? example: SELECT * FROM tbl_name WHERE id_field IN ('value1', 'value2', 'value3', NULL) I want to limit to these four values. I have tried the above statement and it doesn't work, well it executes but doesn't add the records with NULL id_fields. I have also tried to add a OR condition but this just make the query run and run with no end in sight. SELECT * FROM tbl_name WHERE other_condition = bar AND another_condition = foo AND

android BluetoothDevice.getName() return null

断了今生、忘了曾经 提交于 2019-12-28 00:56:30
问题 On sometime, BluetoothDevice.getName() return null. How can i fix it? remoteDeviceName maybe null in following code. And i need distinguish my device and other devices by remoteDeviceName. BluetoothAdapter.getDefaultAdapter().startLeScan(new LeScanCallback() { @Override public void onLeScan(final BluetoothDevice device, final int rssi, byte[] scanRecord) { String remoteDeviceName = device.getName(); Log.d("Scanning", "scan device " + remoteDeviceName); }); 回答1: Finally, i found out the

In either C or C++, should I check pointer parameters against NULL/nullptr?

血红的双手。 提交于 2019-12-27 12:17:51
问题 This question was inspired by this answer. I've always been of the philosophy that the callee is never responsible when the caller does something stupid, like passing of invalid parameters. I have arrived at this conclusion for several reasons, but perhaps the most important one comes from this article: Everything not defined is undefined. If a function doesn't say in it's docs that it's valid to pass nullptr , then you damn well better not be passing nullptr to that function. I don't think

null vs empty string in Oracle [duplicate]

谁说我不能喝 提交于 2019-12-27 12:16:45
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: Why does Oracle 9i treat an empty string as NULL? I have a table in Oracle 10g named TEMP_TABLE with only two columns - id and description just for the sake of demonstration. The column id is a sequence generated primary key of type NUMBER(35, 0) not null and the column DESCRIPTION is a type of VARCHAR2(4000) not null . The basic table structure in this case would look something like the following. +------------

IBOutlet is nil, but it is connected in storyboard, Swift

和自甴很熟 提交于 2019-12-27 11:04:31
问题 Using Swift 1.1 and Xcode 6.2. I have a UIStoryboard containing a singular, custom UIViewController subclass. On it, I have an @IBOutlet connection of type UIView from that controller to a UIView subclass on the storyboard. I also have similar outlets for subviews of that view. See figure A. But at run time, these properties are nil (Figure B). Even though I have assured I've connected the outlets in Interface Builder. Thoughts : Is it possible that because I am using a subclass of a subclass

IBOutlet is nil, but it is connected in storyboard, Swift

荒凉一梦 提交于 2019-12-27 11:04:06
问题 Using Swift 1.1 and Xcode 6.2. I have a UIStoryboard containing a singular, custom UIViewController subclass. On it, I have an @IBOutlet connection of type UIView from that controller to a UIView subclass on the storyboard. I also have similar outlets for subviews of that view. See figure A. But at run time, these properties are nil (Figure B). Even though I have assured I've connected the outlets in Interface Builder. Thoughts : Is it possible that because I am using a subclass of a subclass

Null check chain vs catching NullPointerException

≡放荡痞女 提交于 2019-12-27 11:03:43
问题 A web service returns a huge XML and I need to access deeply nested fields of it. For example: return wsObject.getFoo().getBar().getBaz().getInt() The problem is that getFoo() , getBar() , getBaz() may all return null . However, if I check for null in all cases, the code becomes very verbose and hard to read. Moreover, I may miss the checks for some of the fields. if (wsObject.getFoo() == null) return -1; if (wsObject.getFoo().getBar() == null) return -1; // maybe also do something with

In Objective-C why should I check if self = [super init] is not nil?

馋奶兔 提交于 2019-12-27 10:42:27
问题 I have a general question about writing init methods in Objective-C. I see it everywhere (Apple's code, books, open source code, etc.) that an init method should check if self = [super init] is not nil before continuing with initialisation. The default Apple template for an init method is: - (id) init { self = [super init]; if (self != nil) { // your code here } return self; } Why? I mean when is init ever going to return nil? If I called init on NSObject and got nil back, then something must