Java and Databases

R

Ryan Stewart

Someone posted something about this a while back in one of the
comp.lang.java groups, but I can't find it now. I want to create an object
model backed by a database. Where should the database code go? Should I have
a commit() method in each class, or something like that? That doesn't seem
right. I found some info about JDO (Java Data Objects), but after about half
an hour of browsing, it doesn't seem to be quite what I'm looking for. I may
be wrong though.

What it's for: Soon I intend to begin writing an application which is
primarily for learning purposes, though some use may come of it later on. It
will probably be a webapp using JSP, but there's a very slight possibility
that I'll use applets as an interface instead. I'm doing this at home
entirely on my own. I also intend to look into Struts for the first time.
Will it help with my database code issue?

My reason for asking: I've been involved with webapps where all the code,
including db code, was crammed into a JSP. Talk about *ugly*. I want to
learn the correct way to write a solid, maintainable application
 
C

Christophe Vanfleteren

Ryan said:
Someone posted something about this a while back in one of the
comp.lang.java groups, but I can't find it now. I want to create an object
model backed by a database. Where should the database code go? Should I
have a commit() method in each class, or something like that? That doesn't
seem right. I found some info about JDO (Java Data Objects), but after
about half an hour of browsing, it doesn't seem to be quite what I'm
looking for. I may be wrong though.

What it's for: Soon I intend to begin writing an application which is
primarily for learning purposes, though some use may come of it later on.
It will probably be a webapp using JSP, but there's a very slight
possibility that I'll use applets as an interface instead. I'm doing this
at home entirely on my own. I also intend to look into Struts for the
first time. Will it help with my database code issue?

Not really , Struts is an MVC web framework, it has nothing to do with your
business logic itself.
My reason for asking: I've been involved with webapps where all the code,
including db code, was crammed into a JSP. Talk about *ugly*. I want to
learn the correct way to write a solid, maintainable application

Use hibernate (http://www.hibernate.org) in combination with DAO (Data Acces
Object) classes (a class in which you do basic CRUD operations, so all DB
code is centralised there and encapsulated from other classes).

Combined with Hibernate, you'll barely ever need to write a single line of
SQL, while being able to support a rich domain model, and allowing faster
development.
 
R

Ryan Stewart

Christophe Vanfleteren said:
Not really , Struts is an MVC web framework, it has nothing to do with your
business logic itself.


Use hibernate (http://www.hibernate.org) in combination with DAO (Data Acces
Object) classes (a class in which you do basic CRUD operations, so all DB
code is centralised there and encapsulated from other classes).

Combined with Hibernate, you'll barely ever need to write a single line of
SQL, while being able to support a rich domain model, and allowing faster
development.

Many thanks for the prompt reply. I think DAO is what I was looking for.
I've had some exposure to TopLink, which Hibernate looks very similar to. I
may go that route, or I may take a step down and get into the nitty gritty
of database programming, just for the experience. Maybe get some experience
with reflection as well. Other comments/suggestions still welcome!
 
C

Christophe Vanfleteren

Ryan said:
Many thanks for the prompt reply. I think DAO is what I was looking for.
I've had some exposure to TopLink, which Hibernate looks very similar to.
I may go that route, or I may take a step down and get into the nitty
gritty of database programming, just for the experience. Maybe get some
experience with reflection as well. Other comments/suggestions still
welcome!

You are correct: if you had no JDBC experience before, it is wise to use it
in order to get to know the basic layers (if only to get to see how tedious
it can become :).

But once you know the basics and need to begin a new project, I would
recommend an ORM (Object Relational Mapper) like Hibernate or Toplink, or a
JDO implementation. Assuming ofcourse, that your problem lends itself to an
ORM solution (not everything does).

You can still use a "normal" library on top of JDBC like IBatis or Spring in
those cases, as it still is nicer to work with than raw JDBC.
 
M

Matt Parker

Ryan said:
Someone posted something about this a while back in one of the
comp.lang.java groups, but I can't find it now. I want to create an object
model backed by a database. Where should the database code go? Should I
have a commit() method in each class, or something like that? That doesn't
seem right. I found some info about JDO (Java Data Objects), but after
about half an hour of browsing, it doesn't seem to be quite what I'm
looking for. I may be wrong though.

What it's for: Soon I intend to begin writing an application which is
primarily for learning purposes, though some use may come of it later on.
It will probably be a webapp using JSP, but there's a very slight
possibility that I'll use applets as an interface instead. I'm doing this
at home entirely on my own. I also intend to look into Struts for the
first time. Will it help with my database code issue?

My reason for asking: I've been involved with webapps where all the code,
including db code, was crammed into a JSP. Talk about *ugly*. I want to
learn the correct way to write a solid, maintainable application

I'm currently getting towards the end of writing an OpenSource web
development toolkit, which includes a database abstraction layer. E-mail me
off list if you want to give it a test drive. I've only got Javadocs at the
moment for documentation though. At the very least you'll see how I've
implemented my database pool, wrapped the objects etc.

Matt
 
V

valds

Matt Parker said:
I'm currently getting towards the end of writing an OpenSource web
development toolkit, which includes a database abstraction layer. E-mail me
off list if you want to give it a test drive. I've only got Javadocs at the
moment for documentation though. At the very least you'll see how I've
implemented my database pool, wrapped the objects etc.

Few weeks ago I found interesting enough ide+framework (www.worcsnet.com), guys
used another approach - solid javascript control library for client, including
objects like datawindow from powerbuilder, tonns of other controls and browser
based studio IDE, that they claim, allows to create complex web apps within
days, and apps may function and look like standart standalone client-server app


Regards,
Valds
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top