How to find total column from a resultset?
Answers were Sorted based on User's Feedback
Answer / shankar
int columnCnt = java.sql.ResultSetMetaData.getColumnCount();
Is This Answer Correct ? | 7 Yes | 1 No |
Answer / 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 |
What is getconnection method in java?
What is <discriminator > in Hibernate? How exactly inheritance of Object to Tables can be done? What is the benefits of discriminator?
How can I manage special characters when I execute an insert query?
What is the difference between jdbc and odbc?
How do I retrieve a whole row of data at once, instead of calling an individual ResultSet.getXXX method for each column?
How can we retrieve data from the resultset?
What is the benefit of having jdbcrowset implementation?
Give a way to check that all result sets have bin accessed and update counts are generated by execute method.
Is it possible to connect to multiple databases? Using single statement can we update or extract data from two or three or many databases?
What protocol does jdbc use?
What are drivers available?
DB2 Universal claims to support JDBC 2.0, But I can only get JDBC 1.0 functionality. What can I do?