• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Connection Troubles

 
Amy Phillips
Ranch Hand
Posts: 280
  • Mark post as helpful
  • send pies
  • 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
 
Bosun Bello
Ranch Hand
Posts: 1511
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic