How to find total column from a resultset?

Answer Posted / rajshri

import java.sql.*;

class columncount
{
public static void main(String[]args)
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection
("jdbc:odbc:mydsnname");
Statement st=con.createStatement();
String sql="select * from table_name";

ResultSet rs=st.executeQuery(sql);
ResultSetMetaData rd=rs.getMetaData();
int k=rd.getColumnCount();
System.out.println("no of count is " +k);
}
catch(SQLException e1)
{
System.out.println("not working");
}

Is This Answer Correct ?    5 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Explain Basic Steps in Writing a Java Program Using Jdbc?

596


What are the steps required to execute a query in jdbc?

530


Expalin the method of calling a stored procedure from jdbc.

543


Is java a database?

496


Is uri the same as url?

493






What is jdbc connection string?

505


What are the common jdbc exceptions?

515


What is xe in oracle jdbc url?

539


What is the role of class.forname while loading drivers?

565


I have the choice of manipulating database data using a byte[] or a java.sql.blob. Which has best performance?

483


What are the different types of lockings in jdbc?

500


What is drivermanager in jdbc?

540


What are the new features added to JDBC 4.0?

537


What are jdbc?

544


Which of the attributes in the monitoring tab for a jdbc connection pool in the administrative console tell us how many clients are currently waiting for a connection?

519