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

What is difference between jdbc and odbc?

695


What are the packages are used in jdbc?

780


What does the jdbc resultset interface?

730


How can we execute stored procedures using callablestatement?

683


Why should we close database connections in java?

898


What is JDBC DataSource and what are it’s benefits?

733


Explain the steps in writing a java program using jdbc?

666


What is 2 phase commit?

850


Which Java and java.sql data types map to my specific database types?

754


What is meant by dao?

715


How MS-Access DB can be accessed over a network, using JDBC API?

2197


please tell me the name and url path for type-4 driver ?

2798


Is jdbc a web technology?

673


java based application for hospital management

3616


What is an encrypted internet connection?

689