• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to write a two tier database app in Java?

 
Bazsl Smith
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is my first post so if this is not the right forum for this question please move it and let me know. I am new to Java although I do have object oriented programming experience. I am using NetBeans. I would like to write a two tier database program  using either JavaDB or SQLite. Java is not designed for two tier database apps since there are no data bound controls, the read only JTable being the exception.  I have tried and failed to find a good tutorial or a book that provides a good example. Can anyone point me in the right direction?

I did find one tutorial that provides a simple example of adding rows to a database table using EntityManagerFactory and a JPA Controller but the explanation made no sense. Since all database access must be done in code I don't understand what  purpose EntityManagerFactory and JPA serve. To me writing the SQL to do inserts, updates and deletes seems much simpler. I should mention that I am retired and the app I am writing is for myself and possibly a friend so I am looking for the simple approach. Thanks.

 
Dave Tolls
Ranch Hand
Posts: 2091
15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You probably want to look into plain old JDBC, if you're more comfortable with SQL.
Here's the Oracle JDBC tutorial.  (That is Oracle the company rather than Oracle the product)

What the likes of JPA do for you is to map between rows in your database and objects in your Java program.  They're called ORM frameworks (Object-Relational Mapping).  They essentially hide the SQL stuff and manage your objects (entities) for you.

If this is a relatively small exercise (and don't ask me to define 'small'!) then straight up SQL and handling your own objects is probably a lot simpler.  Especially if, as it sounds like, you already know SQL.
 
Campbell Ritchie
Sheriff
Posts: 51332
86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

I think this discussion would fit better in our databases forum, so shall move it.
 
Bazsl Smith
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks guys. As sometimes happens I found a good article on JPA last night after I posted. I don't need the ORM layer for the small apps I will be writing so I think I will write my own classes to connect the GUI to the database. For me that will be faster and easier than learning JPA.
 
Dave Tolls
Ranch Hand
Posts: 2091
15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It will also give you an idea of what JPA is doing under the hood, as it uses JDBC to do its work anyway.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic