Win a copy of Getting started with Java programming language this week in the Beginning Java forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Java and database use  RSS feed

 
Dwayne Barsotta
Ranch Hand
Posts: 80
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello all, I wasn't sure the best place to put this question.  I am trying to find open source projects that utilize accessing and using an embedded database.  I have understand concept of what needs to be done but I would like to see how people organized the use.  I was thinking a class file for DBConnect that does the work of actually connecting to the data base, but then how do I break down the remainder of the database tasks tasks?  Do I create a database class file for each visible page that contained all the procedures and database related code for each page? 

For example in my Shop Repair management software.  I will have the landing page where as soon as you log into the application it displays a complete set of data, do I create a database class file that does all the data acquisition and sends it through the controller class to the window that displays the data?  Or should I create a single database class that retrieves all the information for every window?  I can't seem to find much documentation on how to actually organize an application that stores and accesses a lot of data as mine will.

Any guidance or direction to open source projects that use embedded databases in the program would be great, this way I can see how others handled this task!

Thank You    
 
Junilu Lacar
Sheriff
Posts: 10692
140
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Search for "layered application architecture"

Database access is one layer of a well structured app. The layer is comprised of multiple objects, each with their own specific job to do. As always let the SOLID design principles guide your decisions.
 
Dwayne Barsotta
Ranch Hand
Posts: 80
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you, yes I have been trying to follow these principles since you iterated them a few weeks ago in another post.  For my project nicj named Tech_Tool.  I created a project net.codeeverything.TechTool.  In that project I have a controller.java class.  this is the class that will start when the application opens.  It is the class that will manage the program. 

I am having a coding writers block here.  I need the application to first connect to a database, then once connected pop-up a login screen.  If the database is not created then I need it created and a different screen presented that allows the original user to enter administrator credentials.  The Administrator will then be able to add regular users as needed.  I was hoping to see example of how others handled accessing the databases in a small program.

My idea so far is to create a "database.java" file as the gateway to the database.  The "database" object can then have a method ".connect()" that would return a value based on if the database had to built or not.  If the database did have to be created then the controller can call the "createAdmin" window where the user enters required information, the data is sent to the control and then added to the database through a method in the database object.

This is my plan so far, my problem right now is the complexity of checking and/or creating the database.  The "database" class file keeps making me add tons of exception handling or several levels of try/catch statements.  The code seems to be getting really complicated.

I was hoping there was some open source projects that use databases similar to mine that handle this kind of connection.  I am using Derby.  Even if someone can help me get started with the actual database connection -> build if not there routine.  My original thought was to include the "create=true" to the DB URL but then how could I tell the controller that it needed to be created so it could open the add admin window?

Sorry I can't add code at the moment, I'm at work.  I will try to add some of my code later.

Thank You all

    
 
Dwayne Barsotta
Ranch Hand
Posts: 80
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How does everyone feel about using "Data Access Object" method for persistent data applications?
 
Knute Snortum
Sheriff
Posts: 3445
85
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I always use them, for anything more than the most trivial case.  It makes life a lot easier.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!