Hot questions for Using Neo4j in jsp

Question:

This is a really simple question and I really don't understand how to do this. I have a form where a user can update information, that information needs to be updated in the database. I keep getting the exception invalid data access resource usage and I know something is wrong with my query. I am using neo4j database. Can anyone help update the fields of an object in the database. Any help would be greatly appreciated.

My form:

<form:form action="dogEdited" method="get">
    <label for="usr">Name:</label>
    <input type="text" class="form-control" value="${updateDog.getName()}" name="name"><br>
    <label for="usr">Weight (lb):</label>
    <input type="text" class="form-control" value="${updateDog.getWeight()}" name="weight"><br>
    <label for="usr">Heartbeat (b/min):</label>
    <input type="text" class="form-control" value="${updateDog.getHeartbeat()}" name="heartbeat"><br>
    <input type="hidden" name="id" value="${updateDog.getId()}"/>
    <div style="text-align: center; display: block;"><input type="submit" class="btn-success" value="Enter" /></div>
</form:form>

My controller:

@RequestMapping(value = "/dogEdited", method = RequestMethod.GET)
    public String editDog(@RequestParam("id") Long id, @ModelAttribute CreateDogs updatedDog,ModelMap model, HttpServletResponse response){
        repo.updateByID(updatedDog);

        return "displayInfo";
    }

My query in database (where the problem occurs):

@Query(value="start n=node({dog}.getId()) set n.weight={dog}.getWeight();")
    void updateByID(@Param("dog") CreateDogs dog);

What I want to do is update all fields or any changed fields with the object passed in as parameter.


Answer:

You can't call methods in cypher as Cypher doesn't know anything about POJOs or Java objects.

e.g. {dog}.getId()

I'd recommend to just pass two parameters for id and weight or a map with {id:3345, weight:24}.

then you can do:

match (n) where id(n) = {dog}.id set n.weight={dog}.weight

Question:

I am trying to display the values of a query by executing the query in Java with Neo4j in a JSP. I created a dynamic web project in Eclipse and added the below Java code and added

neo4j-jdbc-driver-3.3.0.jar

in my build path. I wrote below code is Java.

package com.market.basket;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.LinkedList;

public class marketbasketdao {

public LinkedList<String> selectAll() {
LinkedList<String> products = new LinkedList<String>();
try (Connection con = 
DriverManager.getConnection("jdbc:neo4j:http://localhost:7474/browser/", 
"neo4j", "asdf")) {
String query = "MATCH (N:PRODUCT) RETURN N.productid limit 20";
    try (PreparedStatement stmt = con.prepareStatement(query)) {
           try (ResultSet rs = stmt.executeQuery()) {
           while (rs.next()) {
                System.out.println(rs.getString("N.productid"));
                products.add(rs.getString("N.productid"));
            }
        }
    }
} catch (Exception e1) {
e1.printStackTrace();
}return products;
    }
 }

If I add a main method and call the selectAll(), I get the corresponding values in Eclipse Console.

But when I try to call in JSP, it says

No Suitable driver for "jdbc:neo4j:http://localhost:7474/browser/"

My JSP is simple with below code.

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1" import = "com.market.basket.marketbasketdao ,    
java.util.* " %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" 
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<%
 marketbasketdao dao = new marketbasketdao();
 LinkedList<String> list = dao.selectAll();
 for(int i=0; i<list.size() ; i++){
%>
<%= list.get(i) %>
<% 
}
 %>
</body>
</html>

Please help me in understanding why I am unable to execute and display the values in my JSP.


Answer:

You should get the full jar with dependencies from Neo4j release repository, here. That is: download neo4j-jdbc-2.3.2-jar-with-dependencies.jar file and add it to your classpath.