Opportunities @ sun Sushant Kumar

Friday May 30, 2008

In a career of java developement , we come across many simple techniques, which might look simple to many but are difficult for others to use. Just for example , it took me around two months to get idea of how to create my first database (jdbc) class.

Point to Remember when create a simple database driven project in Netbeans

It might be useful for some , who doesnt package their project properly. Follow the following directory structure
  • db [all database code goes here]
  • beans[all definition of beans goes here]
  • ui[this is user interface part.Developed in swing or jsp]
For a really big project , this structure might need revision. But for small projects (LOC <=5 lacs) it works fine. This structure gives plenty of benefit. Now consider the following architecture for project developement. Let you have n tables in database, one of them being student with following attributes :
  • name (string)
  • roll (string )
  • address (string)
  • phone (string)

How to create classes

Stage #1
  • Create classes for every tables in database.Its better to maintain a direct mapping between java classs property and database table column.
  • Create a constructor (public) with no arg
  • Place these beans classes in beans package.
Stage #2 all classes goes to db package. create a CommonDB class. declare method getConnection() with return type java.sql.Connection ; this should be the only source of connection in ur project. keep this method public. For each class(bean classes) u created in Stage #1, declared methods, like
  • boolean addStudent(beans.Student std)
  • boolean editStudent(beans.Student std)
  • ArrayList searchStudent(String criteria)
etc. Declare all the method u will need in ur project. Stage #3 all classes goes to ui package. Create GUI for every beans. Give controls for all the possible operation you think it sud be (or u are asked for). Link them with the methods declared in db classes. For each method, try catch block (where important) sud give descriptive idea of error. Now if u feel to make change in any component in ur project, u can do so. This is one of the best architecture u can completely rely on. To be continued...
Comments:

Post a Comment:
  • HTML Syntax: NOT allowed