简体   繁体   中英

Unable to connect Neo4j from a JSP

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM