我试图实现一个简单的接口,以便在我的数据库中进行尽可能多的查询但是我不知道该怎么做。该界面有一个按钮,每次单击它时,我都希望在我的数据库上执行查询并将结果返回到我的 JTextArea
在工作代码下方
import java.awt.EventQueue;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.IOException;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextArea;
import javax.swing.border.EmptyBorder;
import org.neo4j.cypher.javacompat.ExecutionEngine;
import org.neo4j.cypher.javacompat.ExecutionResult;
import org.neo4j.graphdb.GraphDatabaseService;
import org.neo4j.graphdb.Node;
import org.neo4j.graphdb.Transaction;
import org.neo4j.graphdb.factory.GraphDatabaseFactory;
import org.neo4j.helpers.collection.IteratorUtil;
import static org.neo4j.kernel.impl.util.FileUtils.deleteRecursively;
public class Frame extends JFrame {
public static final String DB_PATH = "/Volumes/iTanioHD/Users/tanio/Desktop/ciao";
GraphDatabaseService BORO_DB;
private JPanel contentPane;
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
Frame frame = new Frame();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
public Frame() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 794, 653);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
contentPane.setLayout(null);
setContentPane(contentPane);
final JTextArea queryTextArea = new JTextArea();
queryTextArea.setBounds(25, 40, 702, 279);
queryTextArea.setBorder(new EmptyBorder(5, 5, 5, 5));
queryTextArea.setText("start n=node(*) where n.name! = 'my node' return n, n.name");
contentPane.add(queryTextArea);
JLabel cypherQueryLabel = new JLabel("Cypher Query");
cypherQueryLabel.setBounds(25, 12, 105, 23);
contentPane.add(cypherQueryLabel);
final JTextArea resultTextArea = new JTextArea();
resultTextArea.setBounds(25, 351, 702, 171);
resultTextArea.setEditable(false);
resultTextArea.setBorder(new EmptyBorder(5, 5, 5, 5));
contentPane.add(resultTextArea);
JLabel resultLabel = new JLabel("Result:");
resultLabel.setBounds(25, 323, 55, 23);
contentPane.add(resultLabel);
JButton btnNewButton_2 = new JButton("Execute Query");
btnNewButton_2.setBounds(274, 540, 176, 41);
btnNewButton_2.setVisible(true);
contentPane.add(btnNewButton_2);
final GraphDatabaseService db = new GraphDatabaseFactory().newEmbeddedDatabase( DB_PATH );
Neo4jEngine neo4jDB = new Neo4jEngine();
neo4jDB.createBOROGraphOntology(db);
btnNewButton_2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
String resultString;
ExecutionEngine engine = new ExecutionEngine( db );
ExecutionResult result = engine.execute(queryTextArea.getText());
resultString =result.dumpToString();
resultTextArea.setText(resultString);
}
});
}
}