How to get the number of columns in a ResultSet in Java

In Java it is possible to retrieve the number of columns of a ResultSet dinamically, thanks to the ResultSetMetaData class. Here’s an example: // Here you get the conn object. E.g.: // Connection conn = DriverManager.getConnection(...); Statementst=conn.createStatement();ResultSetrs=st.executeQuery("SELECT * FROM your_table");ResultSetMetaDatarsmd=rs.getMetaData();intnumCols=rsmd.getColumnCount();System.out.println("Number of columns in your_table: "+numCols); The previous code retrieves and displays the number of columns of your_table.