# JDBC methods



## Caliraj (Mar 22, 2006)

Hi,
Could anyone let me know the difference b/w ResultSet() and ResultSetMetaData(0 methods?


----------



## Chicon (Jul 29, 2004)

*ResultSet* is an object from which you can retrieve data of a SQL statement

Example :


```
[SIZE=2]
Statement stmt = yourSqlConnection.createStatement();
ResultSet rs = stmt.executeQuery("SELECT ID_NUMBER, NAME FROM YOUR_TABLE WHERE BIRTHDATE = '0000-00-00'");
while (rs.next()) {
    int idNumber = rs.getInt("ID_NUMBER");
    String name = rs.getString("NAME");
    System.out.println("<" + idNumber + " - " + name + ">");
}
[/SIZE]
```
*ResultSetMetaData* is an object that provides informations about the content of a resultset.

Example :


```
[SIZE=2]
Statement stmt = yourSqlConnection.createStatement();
ResultSet rs = stmt.executeQuery("SELECT * FROM YOUR_TABLE"); // such SQL query is vague as it
                                                              // doesn't give you the number of
                                                              // columns, their name and their type
ResulSetMetaData rsmd = new ResultSetMetaData(rs);

int numberColumns = rsmd.getColumnCount(); // it says it all

String columnName = rsmd.getColumnName(3); // it gives the name of the third column of the resultset

boolean test = rsmd.isSearchable(1);       // it checks if the first column can be part of a WHERE clause 


[/SIZE]
```
Also, don't confuse resultsets and arrays :

The number of the first item of an array is 0.
The number of the first column of a resultset is 1.


----------

