This week's book giveaway is in the JavaScript forum.
We're giving away four copies of JavaScript Promises Essentials and have Rami Sarieddine on-line!
See this thread for details.
The moose likes JDBC and the fly likes A bit stuck with my small database design Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of JavaScript Promises Essentials this week in the JavaScript forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "A bit stuck with my small database design" Watch "A bit stuck with my small database design" New topic

A bit stuck with my small database design

Kristjan Toots
Ranch Hand

Joined: Jun 03, 2011
Posts: 59

I'm fairly new to the programming and I am still facing difficulties with OOP based concepts. I am trying to build a small standalone swing application with some database functions. I would be thankful for any kind of pointers and I appreciate any discussion on topic.

What I have so far:
I had in mind that I would create Database class what is responsible for starting my hsql server & making connection to it. Then I thought I would create a separate class where I do all the writing and reading from. Am I going towards the right direction? I've read about MVC design pattern but I can't apply it here can I?

I tried to play around with private static Connection connection object. I thought that when I make it static there would be only one of those. So I could pass that to different class and in such way I can accomplish doing writing / reading from separate class. Ended up with
Server@8813f2]: [Thread[HSQLDB Server @8813f2,5,main]]: run()/openServerSocket(): Address already in use: JVM_Bind

I've created Database class like this:

Please correct my english.
Paul Clapham

Joined: Oct 14, 2005
Posts: 18879

So why did you only make those two variables static? Why aren't the other two variables static, for the same reason? And the methods which use those variables, why aren't they static?
Kristjan Toots
Ranch Hand

Joined: Jun 03, 2011
Posts: 59

Paul Clapham, thank you for your reply.
I don't know why I forgot to make those methods static aswell, anyway, your kind guidance steered me towards a solution.

I remember from somewhere that using a lot of static methods is not recommended. Now, when I have static methods all over the place I don't feel so pleased about my approach like I thought I would.

I'm thankful for suggestions how I should rearrange things. : )
It is sorta covered in the JavaRanch Style Guide.
subject: A bit stuck with my small database design