KickJava   Java API By Example, From Geeks To Geeks.

Java > Java SE, EE, ME > java > sql > ResultSetMetaData

java.sql
Interface ResultSetMetaData

All Known Subinterfaces:
RowSetMetaData
All Known Implementing Classes:
RowSetMetaDataImpl
See Also:
Top Examples, Source Code

static final int columnNoNulls
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


[207]Retrieve the column name from a result set as well as its associated data
By Anonymous on 2003/03/26 19:15:40  Rate
//retrieve the column name from a result set as well as its associated data 
  
  
 Vector v = new Vector (  ) ; 
 ResultSetMetaData meta = r.getMetaData (  ) ; 
 while ( r.next (  )  )  {  
   Hashtable row = new Hashtable (  ) ; 
   for  ( int x = 1; x  < = meta.getColumnCount (  ) ; x++ )  {  
     String column = meta.getColumnName ( x ) ; 
     String value = r.getString ( column ) ; 
     if  ( value == null )  {  
       value=""; 
      }  
     row.put ( column,value.trim (  )  ) ; 
    }  
   v.add ( row ) ; 
  }  
  
  
 //columnNoNulls


static final int columnNullable
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


static final int columnNullableUnknown
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


String getCatalogName(int column)
                      throws SQLException
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


String getColumnClassName(int column)
                          throws SQLException
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


int getColumnCount()
                   throws SQLException
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


[365]Retrieve number of columns from a result set
By Anonymous on 2003/08/20 15:48:07  Rate
ResultSet rs = stmt.executeQuery ( "SELECT a, b, c FROM TABLE2" ) ; 
  ResultSetMetaData rsmd = rs.getMetaData (  ) ; 
  int numberOfColumns = rsmd.getColumnCount (  ) ; 
  boolean b = rsmd.isSearchable ( 1 ) ; 
 


int getColumnDisplaySize(int column)
                         throws SQLException
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


String getColumnLabel(int column)
                      throws SQLException
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


[1894]A simple JDBC MetaData demo
By Anonymous on 2007/06/18 08:13:34  Rate
/******************************************************************************/ 
 /* */ 
 /* FILE: JDBCMetaData.java */ 
 /* */ 
 /* A simple JDBC MetaData demo */ 
 /* =========================== */ 
 /* */ 
 /* V1.00 24-JAN-1999 Te http://www.heimetli.ch */ 
 /* */ 
 /* ------------------------------------------------------------------------- */ 
 /* */ 
 /* This example was coded and tested with JDK1.2.2 */ 
 /* */ 
 /* Access was used as database, over the JDBC-ODBC bridge which comes */ 
 /* with the JDK. */ 
 /* */ 
 /* To run this example, you need a database with the following properties: */ 
 /* = >  no username */ 
 /* = >  no password */ 
 /* = >  a table called "Cust" */ 
 /* = >  a system DSN called "Database" */ 
 /* */ 
 /******************************************************************************/ 
  
  
 import java.sql.* ; 
  
  
 class JDBCMetaData 
  {  
  public static void main (  String args [  ]   )  
   {  
   try 
       {  
       // Load the database driver 
       Class.forName (  "sun.jdbc.odbc.JdbcOdbcDriver"  )  ; 
  
  
       // Get a connection to the database 
       Connection conn = DriverManager.getConnection (  "jdbc:odbc:Database"  )  ; 
  
  
       // Print all warnings 
       for (  SQLWarning warn = conn.getWarnings (  ) ; warn != null; warn = warn.getNextWarning (  )   )  
           {  
           System.out.println (  "SQL Warning:"  )  ; 
           System.out.println (  "State : " + warn.getSQLState (  )    )  ; 
           System.out.println (  "Message: " + warn.getMessage (  )     )  ; 
           System.out.println (  "Error : " + warn.getErrorCode (  )   )  ; 
           }  
  
  
       // Get a statement from the connection 
       Statement stmt = conn.createStatement (  )  ; 
  
  
       // Execute the query 
       ResultSet rs = stmt.executeQuery (  "SELECT * FROM Cust"  )  ; 
  
  
       // Get the metadata 
       ResultSetMetaData md = rs.getMetaData (  )  ; 
  
  
       // Print the column labels 
       for (  int i = 1; i  < = md.getColumnCount (  ) ; i++  )  
          System.out.print (  md.getColumnLabel ( i )  + " "  )  ; 
       System.out.println (  )  ; 
  
  
       // Loop through the result set 
       while (  rs.next (  )   )  
           {  
           for (  int i = 1; i  < = md.getColumnCount (  ) ; i++  )  
              System.out.print (  rs.getString ( i )  + " "  )  ; 
           System.out.println (  )  ; 
           }  
  
  
       // Close the result set, statement and the connection 
       rs.close (  )  ; 
       stmt.close (  )  ; 
       conn.close (  )  ; 
       }  
   catch (  SQLException se  )  
       {  
       System.out.println (  "SQL Exception:"  )  ; 
  
  
       // Loop through the SQL Exceptions 
       while (  se != null  )  
           {  
           System.out.println (  "State : " + se.getSQLState (  )    )  ; 
           System.out.println (  "Message: " + se.getMessage (  )     )  ; 
           System.out.println (  "Error : " + se.getErrorCode (  )   )  ; 
  
  
           se = se.getNextException (  )  ; 
           }  
       }  
   catch (  Exception e  )  
       {  
       System.out.println (  e  )  ; 
       }  
   }  
  } 


String getColumnName(int column)
                     throws SQLException
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


int getColumnType(int column)
                  throws SQLException
See Also:
Types
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


String getColumnTypeName(int column)
                         throws SQLException
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


int getPrecision(int column)
                 throws SQLException
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


int getScale(int column)
             throws SQLException
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


String getSchemaName(int column)
                     throws SQLException
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


String getTableName(int column)
                    throws SQLException
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


boolean isAutoIncrement(int column)
                        throws SQLException
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


boolean isCaseSensitive(int column)
                        throws SQLException
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


boolean isCurrency(int column)
                   throws SQLException
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


boolean isDefinitelyWritable(int column)
                             throws SQLException
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


int isNullable(int column)
               throws SQLException
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


boolean isReadOnly(int column)
                   throws SQLException
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


boolean isSearchable(int column)
                     throws SQLException
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


boolean isSigned(int column)
                 throws SQLException
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


boolean isWritable(int column)
                   throws SQLException
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  

Popular Tags