This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
Let me make it clear:
There is no query that will work on all database systems. Sorry that I made it so big, but the message didn't seem to get through.
So you have two options:
- use a different query for all database systems you want to support (using Google initially to find those queries)
- follow Lester's advice: check out DatabaseMetaData; you can get an instance using Connection.getMetaData(). There is one method that returns a ResultSet for all columns. You then only need to go through the ResultSet, incrementing a counter for each result:
Make sure to close() the ResultSet when done.
Did you check their manual? Specifically, did you check their documentation on system tables? Based on that documentation, I can see that it's possible to find the column count. You'll need admin privileges to query those system tables.