简体   繁体   中英

Creating database desktop application with data manipulation in Netbeans using Java Persistence

It's my first time to use Persistence in developing a Java program because I usually connect via JDBC. I read that for large amounts of data, it is best to use persistence. I tried playing with the CRUD example of Netbeans. It's not very helpful thought because it only connects to the DB and allows addition and deletion of records. I need something that will allow me to manipulate the data like if the value from column C1 of table T1 is such, it will retrieve data from table t2. In short, I need to apply conditions before knowing what to retrieve exactly. The example in CRUD example already has a specific table to retrieve and only acts like a database manager. How is it possible to retrieve a specific item first then from this, will determine the next steps to be done.

I'm also using embedded JavaDB/Derby as my database (also my first time to use because I usually use remote mysql)

I think, you can do that easily with JPA too. Just call in some your created DAO object:

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());

So you could create some method in your DAO that will do a query for your condition and then do update query and so on.

You could also try Geertjan's series of articles 2 and the other articles. But there are some more tricky things (but I am beginner with NB platform and a bit with Java too, and I figured out many things), but it could be done with Derby Embbed too.

Do you need a web application or a desktop application like the netbeans CRUD example?

For the first one you could try http://vaadin.com/wiki/-/wiki/Main/Using%20Hibernate%20with%20Vaadin

For the desktop I suggest to use griffon with db4o or sth.: http://griffon.codehaus.org/Db4o+Plugin or this example http://platform.netbeans.org/tutorials/nbm-crud.html

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