Initially I was doing it the start of each class and reusing the same connection variable. But Derby seemed to auto-close the connection after each statement.
I was burning the midnight oil on it last night. I realize it's not the most efficient way of doing things, but wouldn't this eliminate problems of scope? I'll be looking at it with a fresher head tonight! Rhys -----Original Message----- From: Michael Segel [mailto:[EMAIL PROTECTED] Sent: 03 March 2006 14:46 To: Derby Discussion Subject: Re: No current connection On Friday 03 March 2006 7:58 am, Rhys Campbell wrote: > Hi, > > I have a method called initDatabase() which returns the Connection > variable. When I execute any query against the database I call another > method of which the first parameter is the Connection (i.e. I place > initDatabase() as the parameter. > > i.e. ResultSet rs = database.executeQuery(initDatabase(), "SELECT * FROM > myTable"); (Code from memory!) > > Eeewww. Uhm... initDatabase() is a method within your current class. Ok... By the name of the function, you're implying that you're opening up a data connection each time initDatabase is called.... Lots of overhead that could be adverted if you change the scope of the instance of the Connection object. > Connections are not passed between the main (business logic) classes. > They all have access to a little class called DBTools which I wrote to > simplify DB access. > > I have a play with your ideas this evening and maybe post my code. > Thanks for your thoughts. > > Regards, > > Rhys > > -----Original Message----- > From: Michael Segel [mailto:[EMAIL PROTECTED] > Sent: 03 March 2006 13:36 > To: Rhys Campbell > Subject: Re: No current connection > > On Thursday 02 March 2006 7:20 pm, you wrote: > > Hi, > > > > I'm using Derby for a current project for the first time. Got on with > > it > > > pretty well until tonight. > > > > My app starts up a database, drops a few views and then recreates > > them. > > > When another one of my Java classes moves on to do a small SELECT > > (that > > > should yield a single result). The exception "No current connection" > > is > > > raised with the query obviously failing. > > > > I have checked the Derby.log but I am warned that the file is binary, > > when > > > it opens in my editor, and a load of "junk" is displayed. I did use a > > little tool called "fd" which is a oct / hex character editor. This > > did > > > make some sections of text legible but I couldn't see anything useful > > to > > > explain my issue. > > > > Can anyone offer me any pointers? > > > > Many thanks, > > > > Rhys > > Just to update the post I made... > > Since you mention multiple classes... > > 1) Check the scope of the connection declaration and are you passing it > in as > a parameter of your new class when you instantiate it? > > 2) Are you overwritting your connection in your new class, losing the > connection for that instance of the class variable? > > Again, just shooting from the hip.
