Important Notice: Our web hosting provider recently started charging us for additional visits, which was unexpected. In response, we're seeking donations. Depending on the situation, we may explore different monetization options for our Community and Expert Contributors. It's crucial to provide more returns for their expertise and offer more Expert Validated Answers or AI Validated Answers. Learn more about our hosting issue here.

Java JDBC ResultSet metadata FAQ: How do I dynamically determine the number of columns in a Java/JDBC ResultSet?

0

When you send a SQL SELECT statement to a database using JDBC, you’ll read the query results into a JDBC ResultSet object. We demonstrated how to do this in our article on How to Create and Execute a SQL SELECT Query. In some database programs you’ll need to go a bit further, and dynamically determine the number of columns that are in a Java ResultSet object. As an example, I’ve been working on a Contact Management servlet-based Intranet application. Because I can dynamically determine the number of columns returned from my queries, I can write one QueryServlet to handle all of my database query needs. This makes it very easy to create a simple report writer for my Intranet app. The way you accomplish this is by working with the Java JDBC metadata.

Related Questions

Thanksgiving questions

*Sadly, we had to bring back ads too. Hopefully more targeted.