This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin for Android App Development and have Peter Sommerhoff on-line!
See this thread for details.
Win a copy of Kotlin for Android App Development this week in the Kotlin forum!
  • 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 ...
  • Campbell Ritchie
  • Liutauras Vilda
  • Devaka Cooray
  • Jeanne Boyarsky
  • Bear Bibeault
  • Junilu Lacar
  • Paul Clapham
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • salvin francis
  • Carey Brown
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

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).]
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).]
All of the world's problems can be solved in a garden - Geoff Lawton. Tiny ad:
RavenDB is an Open Source NoSQL Database that’s fully transactional (ACID) across your database
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!