• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

A bit stuck with my small database design

 
Ranch Hand
Posts: 59
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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:


 
Sheriff
Posts: 28322
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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. : )
 
We don't have time to be charming! Quick, read this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic