Followers

JDBC : ResultSetMetaData interface

package com.pack1;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.sql.Statement;

public class ResultSetMetaDataEx {
    public static void main(String[] args) throws ClassNotFoundException,SQLException{
        Connection con = null;
        Statement stmt = null;
        ResultSet rs = null;
            Class.forName("org.apache.derby.jdbc.ClientDriver");
            String url = "jdbc:derby://localhost:1527/hari";
           con = DriverManager.getConnection(url, "app","app");
            stmt = con.createStatement();                      
            String query = "select * from MYEMP";
            rs = stmt.executeQuery(query);
            ResultSetMetaData rsmd = rs.getMetaData();
            int count = rsmd.getColumnCount();
           // System.out.println(count);
            for(int i= 1;i<= count;i++){
            System.out.println(rsmd.getColumnName(i)+" "+rsmd.getColumnTypeName(i)+" "+
              rsmd.getColumnDisplaySize(i)+" "+rsmd.getTableName(i));
            
            System.out.println(rs.getRow());
            }
        } 
    }
   

No comments:

Post a Comment