1. /*
  2. * @(#)ResultSetMetaData.java 1.26 03/01/23
  3. *
  4. * Copyright 2003 Sun Microsystems, Inc. All rights reserved.
  5. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  6. */
  7. package java.sql;
  8. /**
  9. * An object that can be used to get information about the types
  10. * and properties of the columns in a <code>ResultSet</code> object.
  11. * The following code fragment creates the <code>ResultSet</code> object rs,
  12. * creates the <code>ResultSetMetaData</code> object rsmd, and uses rsmd
  13. * to find out how many columns rs has and whether the first column in rs
  14. * can be used in a <code>WHERE</code> clause.
  15. * <PRE>
  16. *
  17. * ResultSet rs = stmt.executeQuery("SELECT a, b, c FROM TABLE2");
  18. * ResultSetMetaData rsmd = rs.getMetaData();
  19. * int numberOfColumns = rsmd.getColumnCount();
  20. * boolean b = rsmd.isSearchable(1);
  21. *
  22. * </PRE>
  23. */
  24. public interface ResultSetMetaData {
  25. /**
  26. * Returns the number of columns in this <code>ResultSet</code> object.
  27. *
  28. * @return the number of columns
  29. * @exception SQLException if a database access error occurs
  30. */
  31. int getColumnCount() throws SQLException;
  32. /**
  33. * Indicates whether the designated column is automatically numbered, thus read-only.
  34. *
  35. * @param column the first column is 1, the second is 2, ...
  36. * @return <code>true</code> if so; <code>false</code> otherwise
  37. * @exception SQLException if a database access error occurs
  38. */
  39. boolean isAutoIncrement(int column) throws SQLException;
  40. /**
  41. * Indicates whether a column's case matters.
  42. *
  43. * @param column the first column is 1, the second is 2, ...
  44. * @return <code>true</code> if so; <code>false</code> otherwise
  45. * @exception SQLException if a database access error occurs
  46. */
  47. boolean isCaseSensitive(int column) throws SQLException;
  48. /**
  49. * Indicates whether the designated column can be used in a where clause.
  50. *
  51. * @param column the first column is 1, the second is 2, ...
  52. * @return <code>true</code> if so; <code>false</code> otherwise
  53. * @exception SQLException if a database access error occurs
  54. */
  55. boolean isSearchable(int column) throws SQLException;
  56. /**
  57. * Indicates whether the designated column is a cash value.
  58. *
  59. * @param column the first column is 1, the second is 2, ...
  60. * @return <code>true</code> if so; <code>false</code> otherwise
  61. * @exception SQLException if a database access error occurs
  62. */
  63. boolean isCurrency(int column) throws SQLException;
  64. /**
  65. * Indicates the nullability of values in the designated column.
  66. *
  67. * @param column the first column is 1, the second is 2, ...
  68. * @return the nullability status of the given column; one of <code>columnNoNulls</code>,
  69. * <code>columnNullable</code> or <code>columnNullableUnknown</code>
  70. * @exception SQLException if a database access error occurs
  71. */
  72. int isNullable(int column) throws SQLException;
  73. /**
  74. * The constant indicating that a
  75. * column does not allow <code>NULL</code> values.
  76. */
  77. int columnNoNulls = 0;
  78. /**
  79. * The constant indicating that a
  80. * column allows <code>NULL</code> values.
  81. */
  82. int columnNullable = 1;
  83. /**
  84. * The constant indicating that the
  85. * nullability of a column's values is unknown.
  86. */
  87. int columnNullableUnknown = 2;
  88. /**
  89. * Indicates whether values in the designated column are signed numbers.
  90. *
  91. * @param column the first column is 1, the second is 2, ...
  92. * @return <code>true</code> if so; <code>false</code> otherwise
  93. * @exception SQLException if a database access error occurs
  94. */
  95. boolean isSigned(int column) throws SQLException;
  96. /**
  97. * Indicates the designated column's normal maximum width in characters.
  98. *
  99. * @param column the first column is 1, the second is 2, ...
  100. * @return the normal maximum number of characters allowed as the width
  101. * of the designated column
  102. * @exception SQLException if a database access error occurs
  103. */
  104. int getColumnDisplaySize(int column) throws SQLException;
  105. /**
  106. * Gets the designated column's suggested title for use in printouts and
  107. * displays.
  108. *
  109. * @param column the first column is 1, the second is 2, ...
  110. * @return the suggested column title
  111. * @exception SQLException if a database access error occurs
  112. */
  113. String getColumnLabel(int column) throws SQLException;
  114. /**
  115. * Get the designated column's name.
  116. *
  117. * @param column the first column is 1, the second is 2, ...
  118. * @return column name
  119. * @exception SQLException if a database access error occurs
  120. */
  121. String getColumnName(int column) throws SQLException;
  122. /**
  123. * Get the designated column's table's schema.
  124. *
  125. * @param column the first column is 1, the second is 2, ...
  126. * @return schema name or "" if not applicable
  127. * @exception SQLException if a database access error occurs
  128. */
  129. String getSchemaName(int column) throws SQLException;
  130. /**
  131. * Get the designated column's number of decimal digits.
  132. *
  133. * @param column the first column is 1, the second is 2, ...
  134. * @return precision
  135. * @exception SQLException if a database access error occurs
  136. */
  137. int getPrecision(int column) throws SQLException;
  138. /**
  139. * Gets the designated column's number of digits to right of the decimal point.
  140. *
  141. * @param column the first column is 1, the second is 2, ...
  142. * @return scale
  143. * @exception SQLException if a database access error occurs
  144. */
  145. int getScale(int column) throws SQLException;
  146. /**
  147. * Gets the designated column's table name.
  148. *
  149. * @param column the first column is 1, the second is 2, ...
  150. * @return table name or "" if not applicable
  151. * @exception SQLException if a database access error occurs
  152. */
  153. String getTableName(int column) throws SQLException;
  154. /**
  155. * Gets the designated column's table's catalog name.
  156. *
  157. * @param column the first column is 1, the second is 2, ...
  158. * @return the name of the catalog for the table in which the given column
  159. * appears or "" if not applicable
  160. * @exception SQLException if a database access error occurs
  161. */
  162. String getCatalogName(int column) throws SQLException;
  163. /**
  164. * Retrieves the designated column's SQL type.
  165. *
  166. * @param column the first column is 1, the second is 2, ...
  167. * @return SQL type from java.sql.Types
  168. * @exception SQLException if a database access error occurs
  169. * @see Types
  170. */
  171. int getColumnType(int column) throws SQLException;
  172. /**
  173. * Retrieves the designated column's database-specific type name.
  174. *
  175. * @param column the first column is 1, the second is 2, ...
  176. * @return type name used by the database. If the column type is
  177. * a user-defined type, then a fully-qualified type name is returned.
  178. * @exception SQLException if a database access error occurs
  179. */
  180. String getColumnTypeName(int column) throws SQLException;
  181. /**
  182. * Indicates whether the designated column is definitely not writable.
  183. *
  184. * @param column the first column is 1, the second is 2, ...
  185. * @return <code>true</code> if so; <code>false</code> otherwise
  186. * @exception SQLException if a database access error occurs
  187. */
  188. boolean isReadOnly(int column) throws SQLException;
  189. /**
  190. * Indicates whether it is possible for a write on the designated column to succeed.
  191. *
  192. * @param column the first column is 1, the second is 2, ...
  193. * @return <code>true</code> if so; <code>false</code> otherwise
  194. * @exception SQLException if a database access error occurs
  195. */
  196. boolean isWritable(int column) throws SQLException;
  197. /**
  198. * Indicates whether a write on the designated column will definitely succeed.
  199. *
  200. * @param column the first column is 1, the second is 2, ...
  201. * @return <code>true</code> if so; <code>false</code> otherwise
  202. * @exception SQLException if a database access error occurs
  203. */
  204. boolean isDefinitelyWritable(int column) throws SQLException;
  205. //--------------------------JDBC 2.0-----------------------------------
  206. /**
  207. * <p>Returns the fully-qualified name of the Java class whose instances
  208. * are manufactured if the method <code>ResultSet.getObject</code>
  209. * is called to retrieve a value
  210. * from the column. <code>ResultSet.getObject</code> may return a subclass of the
  211. * class returned by this method.
  212. *
  213. * @param column the first column is 1, the second is 2, ...
  214. * @return the fully-qualified name of the class in the Java programming
  215. * language that would be used by the method
  216. * <code>ResultSet.getObject</code> to retrieve the value in the specified
  217. * column. This is the class name used for custom mapping.
  218. * @exception SQLException if a database access error occurs
  219. * @since 1.2
  220. */
  221. String getColumnClassName(int column) throws SQLException;
  222. }