• 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
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

Connection Troubles

 
Ranch Hand
Posts: 280
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am trying to get my database connection sorted out - i can create the conenction and all works fine but I will need to connect to the databse from a number of files and don't want to have to keep copying the code so I am trying to move my connection code into a class and have the other classes call it - not sure if this will technically work. Would it be easier to go with a connection pool?
Anyway this is what I ahve so far - both parts sort of work but i can't get them to talk to each other
Connection Code

Query Code

Any tips would be very welcome
Thanks
 
Ranch Hand
Posts: 1512
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In what seems to be the constructor for the Connect class, you are doing this: return connection
First of all, a constructor should not be returning a value bacause it implicitly returns a reference "this" to the class.
In your TableDisplay class, this Connect.Connect(); is actually a method call. Bottom line is you should be returning the collection object from within a method. And all this compiled?
 
Amy Phillips
Ranch Hand
Posts: 280
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
Thanks for your pointers, I now understand why it doesn't work but am a bit unclear as to how to get it working. Firstly should I be creating this connection class at all? secondly what do I do to the connection class to allow the other classes to request and receive a connection
Thanks
 
Amy Phillips
Ranch Hand
Posts: 280
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ahhh have finally realised where its all going wrong. I think i am approaching this problem from the wrong direction! Thanks for all your help
 
rubbery bacon. rubbery tiny ad:
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
https://coderanch.com/t/751654/free-earth-friendly-heat-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic