English 中文(简体)
使用Java Persistence在NetBeans中创建具有数据操作功能的数据库桌面应用程序
原标题:Creating database desktop application with data manipulation in Netbeans using Java Persistence

这是我第一次在开发Java程序中使用Persistence,因为我通常是通过JDBC连接。我读到说对于大量数据最好使用persistence。我尝试玩NetBeans的CRUD示例。它没什么用,因为它只连接到数据库并允许添加和删除记录。我需要一些可以让我像从表T1的列C1中检索数据一样处理数据的东西。简而言之,在知道要检索什么之前,我需要应用条件。CRUD示例中的示例已经有一个具体的表要检索,只充当数据库管理器。如何先检索特定项,然后确定要执行的下一步呢?

我也使用内嵌的JavaDB/Derby作为我的数据库(这也是我第一次使用,因为我通常使用远程mysql)

问题回答

我觉得,你也可以轻松地用JPA来实现。只需调用一些你创建的DAO对象即可:

javax.persistence.EntityManager em = Persistence.createEntityManagerFactory("MyDBPU").createEntityManager();
javax.persistence.Query query = em.createQuery("SELECT t FROM Table1 t");
em.getTransaction().begin();
List<Table1Entity> resultList = query.getResultList();

Where the query could be anything, just study the JP Language here: enter link description here. You can have for example something like this:

em.createQuery("SELECT ch FROM Chapters ch WHERE ch.parentChap = "+parentChapter.getChapId());

所以,你可以在DAO中创建一些方法来查询你的条件,然后执行更新查询等操作。

您还可以尝试Geertjan的一系列文章2和其他文章。但是还有一些更棘手的问题(但我是NB平台的初学者,Java也只是有点了解,但我已经解决了许多问题),但也可以使用Derby Embbed。

你们是否需要网络应用程序或像净户人CRUD那样的桌面应用?

对于第一个,您可以尝试http://vaadin.com/wiki/-/wiki/Main/Using%20Hibernate%20with%20Vaadin

对于桌面应用程序,我建议使用带有db4o插件的griffon或其他东西:http://griffon.codehaus.org/Db4o+Plugin或者这个示例http://platform.netbeans.org/tutorials/nbm-crud.html





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签