import java.sql.*;
public class Neo4jJdbcExample {
public static void main(String[] args) {
Connection connection = null;
try {
String url = "jdbc:neo4j:bolt://localhost";
String username = "neo4j";
String password = "password";
connection = DriverManager.getConnection(url, username, password);
Statement stmt = connection.createStatement();
String query = "MATCH (n) RETURN n";
ResultSet rs = stmt.executeQuery(query);
while (rs.next()) {
String nodeLabel = rs.getString("n.name");
System.out.println("Node label: " + nodeLabel);
}
rs.close();
stmt.close();
} catch (SQLException e) {
e.printStackTrace();
} finally {
if (connection != null) {
try {
connection.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
}
}
import java.sql.*;
public class Neo4jJdbcExample {
public static void main(String[] args) {
Connection connection = null;
try {
String url = "jdbc:neo4j:bolt://localhost";
String username = "neo4j";
String password = "password";
connection = DriverManager.getConnection(url, username, password);
Statement stmt = connection.createStatement();
String query = "CREATE (n:Person {name: 'John Doe'})";
stmt.executeUpdate(query);
stmt.close();
} catch (SQLException e) {
e.printStackTrace();
} finally {
if (connection != null) {
try {
connection.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
}
}