Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
05-18-2022 10:14 PM
Hi,
Im using neo4j java driver version 4.3.3. im not sure how to print the query being executed with values. Let consider the below usecase.
the query is as follows,
MATCH (p:Person {name : "John"}) RETURN p
the java code is as follows,
String query = "MATCH (p:Person {name : $name}) RETURN";
try (Session session = this.driver.session()) {
try (Transaction tx = session.beginTransaction()) {
tx.run (query, parameters(name , "John"));
tx.commit();
}
}
now printing the String variable query don't have values. i tried if i can interpolate the parameters with the string.
still not sure how to achieve that. please help me resolve this issue. because logging the queries being executed is crucial to the application.
Regards,
Murali V
06-28-2022 06:45 AM
any inputs? i still cannot solve this problem.
06-29-2022 02:10 AM
Hi @murali_venugopa ,
Even down to the query.log into the DB, you will see the parametrized query plus parameters. Up in your application layer, you can create you own interpolation of query and parameters in order to log so. Something like:
public void logQuery(String query, Map<String, Object params){
for(Map.Entry entry : params.asMap().entrySet())
query = query.replace('$'+entry.getKey().toString(),entry.getValue().toString());
logger.debug(query);
}
public void run(String... args) {
String query = "MATCH (p:Person {name : $name}) RETURN p";
try (Session session = this.driver.session()) {
try (Transaction tx = session.beginTransaction()) {
Value params = parameters("name" , "John");
tx.run (query, params);
tx.commit();
logQuery(query, params)
}
}
}
All the sessions of the conference are now available online