Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

A bit stuck with my small database design

 
Kristjan Toots
Ranch Hand
Posts: 59
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello.
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():
java.net.BindException: Address already in use: JVM_Bind




I've created Database class like this:


 
Paul Clapham
Sheriff
Posts: 21318
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 59
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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. : )
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic