OResultSet Null

#1

Hi,

I following this toturial https://orientdb.com/docs/3.0.x/java/Java-Query-API.html and when I use a SQL statements as a string concatenation I get data in my OResultSet but when I use named paremeters or positional parameters I get a null OResultSet.

Someone can support me with this.

Thanks

mykpt

#2

Hi @mikpt

Thank you for joining OrientDB community!
Can you please post some sample code to reproduce the problem?

Thanks

Luigi

#3

Hi @luigidellaquila,

Thank you for your attention to my problem.

Look this is the idea of what I did …

public class MyClass {

private Logger logger = .... ;


public List<OResult> getData(String key1, String value1, String key2, Boolean value2) {

List<OResult> data = null;
Map<String, Object> params = new HashMap<>();
params.put(key1, value1);
params.put(key2, value2);

StringBuilder query1 = new StringBuilder("Select From USERS Where " + key1 + "like '%" + value1 + "%' And " + key2 + " = " + value2);
StringBuilder query2 = new StringBuilder("Select From USERS Where username like '%:username%' And active =:active");

	/*
	try ( OResultSet rs = ((ODatabaseSession)conn).query(String.valueOf(query1)  {

		//ResultSet have data
		data = rs.stream().collect(Collectors.toList());
	
	} 
	*/
	
	try ( OResultSet rs = ((ODatabaseSession)conn).query(String.valueOf(query2, params)  {
	
		// ResultSet it's NULL
		params.forEach((k,v) -> logger.info("key: " + k + ", value: " + v));
		data = rs.stream().collect(Collectors.toList());
	
	} 

return data;
}

}

Thanks

#4

Hi @mikpt

I see one thing that is not correct here:

StringBuilder query2 = new StringBuilder("Select From USERS Where username like '%:username%' And active =:active");

This is not correct usage of input params, you should change it as follows:

StringBuilder query2 = new StringBuilder("Select From USERS Where username like '%' + :username + '%' And active = :active");

But it does not explain the problem. A result set can be empty, but there is no chance for it to be null at that stage. I think I need a complete test case to replicate it

Thanks

Luigi

#5

Hi @luigidellaquila

You are right, it work. I get resultset with data.

Thanks

mykpt