You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
OrientDB Version: latest git version (commit d6fb8ec)
Java Version: 1.8.0_121-b13
OS: Windows 10
Expected behavior
I have a class myV with a property myBool which is of type Boolean. There are two records of type myV, the first record contains has a value for myBool (false) and the second record has myBool = null.
When I retrieve these records through the JDBC interface, I believe that I should be able to write:
// Execute query
Statement s = conn.createStatement();
ResultSet r = s.executeQuery("SELECT myBool FROM myV");
// Obtain meta data
ResultSetMetaData m = r.getMetaData();
int nCols = m.getColumnCount();
// Get the column types once and store them in an array
int colTypes[] = new int[nCols];
for (int i=0;i<nCols;i++) {
colTypes[i] = m.getColumnType(i+1);
}
// Go through all rows and columns
while(r.next()) {
for (int i=0;i<nCols;i++) {
switch (colTypes[i]) {
case java.sql.Types.BOOLEAN:
boolean b = r.getBoolean(i+1);
System.out.println(b);
break;
default:
Object obj = r.getObject(i+1);
System.out.println(obj);
break;
}
}
}
r.close();
s.close();
There are three important assumptions/points in this code:
I only have to determine the types of the columns once; I mean this cannot change per row, right?
If the type is BOOLEAN, I should retrieve the value with getBoolean.
In my real code I have case statements for other types as well, not shown here, plus, also, shown here, always a fallback which uses getObject, which should always work.
Actual behavior
This errors out with
Exception in thread "main" java.sql.SQLException: An error occurred during the retrieval of the boolean value at column 'myBool' ---> {"@type":"d","@version":0,"myBool":null}
at com.orientechnologies.orient.jdbc.OrientJdbcResultSet.getBoolean(OrientJdbcResultSet.java:379)
at com.orientechnologies.orient.jdbc.OrientJdbcResultSet.getBoolean(OrientJdbcResultSet.java:369)
at Main.main(Main.java:21)
Caused by: java.lang.NullPointerException
at com.orientechnologies.orient.jdbc.OrientJdbcResultSet.getBoolean(OrientJdbcResultSet.java:375)
... 2 more
The problem here is that getBoolean fails when the actual data is null.
Note by the way, that if I do not "cache" the column types and use m.getColumnType inside the while-loop, that getColumnType will return 0 once the second row is reached; which gets me into the default case which then works correctly. But the type of a column should not be changing when going through the rows, right?
Proposed fix
For now, I actually made a change to the JDBC driver, updated getBoolean to use Boolean object instead of boolean primitive and return false if value was null:
public boolean getBoolean(String columnLabel) throws SQLException {
try {
Boolean r = result.getProperty(columnLabel);
if (r==null) {
lastReadWasNull = true;
return false;
} else {
return r;
}
} catch (Exception e) {
throw new SQLException(
"An error occurred during the retrieval of the boolean value at column '" + columnLabel + "' ---> " + result.toElement()
.toJSON(), e);
}
}
The text was updated successfully, but these errors were encountered:
OrientDB Version: latest git version (commit d6fb8ec)
Java Version: 1.8.0_121-b13
OS: Windows 10
Expected behavior
I have a class myV with a property myBool which is of type Boolean. There are two records of type myV, the first record contains has a value for myBool (false) and the second record has myBool = null.
When I retrieve these records through the JDBC interface, I believe that I should be able to write:
There are three important assumptions/points in this code:
I only have to determine the types of the columns once; I mean this cannot change per row, right?
If the type is BOOLEAN, I should retrieve the value with getBoolean.
In my real code I have case statements for other types as well, not shown here, plus, also, shown here, always a fallback which uses getObject, which should always work.
Actual behavior
This errors out with
The problem here is that getBoolean fails when the actual data is null.
Note by the way, that if I do not "cache" the column types and use m.getColumnType inside the while-loop, that getColumnType will return 0 once the second row is reached; which gets me into the default case which then works correctly. But the type of a column should not be changing when going through the rows, right?
Proposed fix
For now, I actually made a change to the JDBC driver, updated getBoolean to use
Boolean
object instead ofboolean
primitive and return false if value was null:The text was updated successfully, but these errors were encountered: