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

List some new features available in jdbc 4.0?

687


What do you understand by jdbc datasource?

802


Write an sql to find all records having all numeric characters in a field ?

744


Explain the process of creating tables using NetBeans IDE?

722


What is @entity in java?

728


What is metadata in java programming?

688


What is odbc. how is it related to sql cli?

806


State the different connection methods used for creating different types of sql.

771


How do I know which jdbc driver to use?

782


How can I determine the isolation levels supported by my DBMS?

752


Is it possible to connect to multiple databases? Using single statement can we update or extract data from two or three or many databases?

819


Why hibernate is better than jdbc?

706


What are the three parts of a jdbc url?

784


How does a file store compare with a jdbc store?

888


What causes no suitable driver error?

745