0

I've just finished a book on MySQL and I'm in the infantile stages of learning to couple that with Java. I know that the technology I need to learn is called JDBC and that it essentially allows you to execute programmatically created SQL statements. I plan on making a database centered records keeping and management program as a long term project. I'm not quite sure how to fit in a program structure to interact with the database.

Why is the typical way this is done, in terms of high level organization?

How do I go about organizing classes to put together SQL statements and work with them and trade info back and forth with the program and handle results?

What are some do's and more importantly, what are some don'ts?

closed as too broad by gnat, durron597, user22815, Bart van Ingen Schenau, user40980 Apr 6 '15 at 16:48

Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • 1
    The usual way is with an ORM, or with DAO objects. See also Domain-Driven Design. – Robert Harvey Apr 6 '15 at 15:24
  • recommended reading: Green fields, blue skys, and the white board - what is too broad? – gnat Apr 6 '15 at 15:25
  • @gnat While I feel that this question is on the borderline, I'd argue that because I gave a specific intended usage, I think that answers can be created. For example, I suspect some typical design patters exists, such as something like MVC for database interaction. I suspect there are thinks like common pitfalls that new programmers encounter as well. – Bassinator Apr 6 '15 at 15:27
  • 1
    I already gave you two design patterns: ORM and DAO. MVC is primarily a UI pattern; it generally uses ORM in the Model. – Robert Harvey Apr 6 '15 at 15:29
  • @RoberHarvey I saw, and I will have to read about them. I was not suggesting that MVC was an appropriate pattern here. I'm just saying that I suspected some widely know patter probably exists for what I want. It is extremely hard to google something when you don't even know what you are looking for. It's like trying to google an instrumental song. The only real way to find what you need is to either listen to every song ever, or find someone who knows. – Bassinator Apr 6 '15 at 15:33
3

A typical "MVC for the web" program might look something like this:

RDBMS <--> ORM <--> DAL/SL <--> Controller <--> ViewModel <--> View

RDBMS - Your database, usually something like SQL Server, Oracle or Postgresql.

ORM - An Object-Relational Mapper, like Hibernate. The ORM converts tables to class objects, and vice versa.

DAL/SL - Data Access layer/Service Layer/Repository. This is a layer of abstraction between your DAL and your User Interface that provides data retrieval services, business logic, and so forth.

ViewModel - The View Model maps data between your domain objects and a user interface. It can also contain user-interface logic.

View - The User Interface.

That ought to keep you busy for awhile.

Not the answer you're looking for? Browse other questions tagged or ask your own question.