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