1

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)

Lulu
  • 11
  • 1
  • 2

2 Answers2

1

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 articles2 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.

0

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

Karussell
  • 17,085
  • 16
  • 97
  • 197
  • I'm developing a database desktop application like CRUD except I want data manipulation rather than a simple data management system. Thanks for these links. Will check them out :) – Lulu Mar 04 '10 at 14:41
  • There are multiple persistence options in Griffon, see http://artifacts.griffon-framework.org/tags/plugin/persistence some of those provide ORM like capabilities http://artifacts.griffon-framework.org/tags/plugin/orm – Andres Almiray Nov 20 '12 at 07:33