This week's book giveaway is in the Agile and Other Processes forum.
We're giving away four copies of The Journey To Enterprise Agility and have Daryl Kulak & Hong Li on-line!
See this thread for details.
Win a copy of The Journey To Enterprise Agility this week in the Agile and Other Processes forum! And see the welcome thread for 20% off.
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

Connection _very_ slow  RSS feed

 
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
so, after many confused hours, i finally got jdbc:postgresql working. But the first thing i noticed was that it took a very long time to download the results of my query... and furthermore, it didnt help that i left out SELECTing the columns which are usually the largest...
Does anyone have any tips for optimizations? should i query for the whole table at once? does jdbc have to do any connection-stuff each time i run a query?
[This message has been edited by Jesper Ottosson (edited April 08, 2000).]
 
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, I know little about optimizing SQL, and nothing at all about postgresql in particular. But offhand: keep the number of different connections to the minimum you can get away with. Often you can just create a single connection once, and then keep re-using the same connection for different queries. The only reasons I've ever had for multiple connections are if you need to be daling with more than one query or resultset at a time, or more than one database. Dunno if you're creating multiple connections, but if you are it can eat up a lot of time.
Also, try using PreparedStatements rather than Statements if you're running the same type of query many times with different inputs. You save on the time the DB spends interpreting your SQL and figuring out how to optimize it. Dunno how much effect this has, but I'd think it would be noticeable at least.
Should you query for the whole table at once? Umm, I guess it depends how much of the table you need. (And is anyone else trying to access the table while you've got it locked, assuming you have some sort of locking?) I usually try to select all the rows I know I will need into one big ResultSet, and loop through it to process each row as necessary. If there are other statements to execute as well, that's when you need another connection, as your first connection is still holding the results if your earlier query. I've always assumed (but never really tested) that this is faster than selecting each row individually. But if the table is particularly huge then memory restrictions could prevent this, or other users needing to access the table may restrict you to one row at a time. And I'm sure there are other considerations I haven't encountered.
If you're already minimizing the number of connections and using PreparedStatements, you may want to post some code to show what exactly you're doing. I personally will be out of town shortly for a week or so, but I'm sure others will have suggestions. Good luck.
[This message has been edited by Jim Yingst (edited April 08, 2000).]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!