1. /*
  2. * @(#)Blob.java 1.17 00/02/02
  3. *
  4. * Copyright 1998-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. * The representation (mapping) in
  13. * the Java<sup><font size=-2>TM</font></sup> programming
  14. * language of an SQL
  15. * <code>BLOB</code> value. An SQL <code>BLOB</code> is a built-in type
  16. * that stores a Binary Large Object as a column value in a row of
  17. * a database table. The driver implements <code>Blob</code> using
  18. * an SQL <code>locator(BLOB)</code>, which means that a
  19. * <code>Blob</code> object contains a logical pointer to the
  20. * SQL <code>BLOB</code> data rather than the data itself.
  21. * A <code>Blob</code> object is valid for the duration of the
  22. * transaction in which is was created.
  23. *
  24. * <P>Methods in the interfaces {@link ResultSet},
  25. * {@link CallableStatement}, and {@link PreparedStatement}, such as
  26. * <code>getBlob</code> and <code>setBlob</code> allow a programmer to
  27. * access an SQL <code>BLOB</code> value.
  28. * The <code>Blob</code> interface provides methods for getting the
  29. * length of an SQL <code>BLOB</code> (Binary Large Object) value,
  30. * for materializing a <code>BLOB</code> value on the client, and for
  31. * determining the position of a pattern of bytes within a
  32. * <code>BLOB</code> value.
  33. *<P>
  34. * This class is new in the JDBC 2.0 API.
  35. * @since 1.2
  36. */
  37. public interface Blob {
  38. /**
  39. * Returns the number of bytes in the <code>BLOB</code> value
  40. * designated by this <code>Blob</code> object.
  41. * @return length of the <code>BLOB</code> in bytes
  42. * @exception SQLException if there is an error accessing the
  43. * length of the <code>BLOB</code>
  44. * @since 1.2
  45. * @see <a href="package-summary.html#2.0 API">What Is in the JDBC 2.0 API</a>
  46. */
  47. long length() throws SQLException;
  48. /**
  49. * Returns as an array of bytes, part or all of the <code>BLOB</code>
  50. * value that this <code>Blob</code> object designates. The byte
  51. * array contains up to <code>length</code> consecutive bytes
  52. * starting at position <code>pos</code>.
  53. * @param pos the ordinal position of the first byte in the
  54. * <code>BLOB</code> value to be extracted; the first byte is at
  55. * position 1
  56. * @param length the number of consecutive bytes to be copied
  57. * @return a byte array containing up to <code>length</code>
  58. * consecutive bytes from the <code>BLOB</code> value designated
  59. * by this <code>Blob</code> object, starting with the
  60. * byte at position <code>pos</code>
  61. * @exception SQLException if there is an error accessing the
  62. * <code>BLOB</code>
  63. * @since 1.2
  64. * @see <a href="package-summary.html#2.0 API">What Is in the JDBC 2.0 API</a>
  65. */
  66. byte[] getBytes(long pos, int length) throws SQLException;
  67. /**
  68. * Retrieves the <code>BLOB</code> designated by this
  69. * <code>Blob</code> instance as a stream.
  70. * @return a stream containing the <code>BLOB</code> data
  71. * @exception SQLException if there is an error accessing the
  72. * <code>BLOB</code>
  73. * @since 1.2
  74. * @see <a href="package-summary.html#2.0 API">What Is in the JDBC 2.0 API</a>
  75. */
  76. java.io.InputStream getBinaryStream () throws SQLException;
  77. /**
  78. * Determines the byte position at which the specified byte
  79. * <code>pattern</code> begins within the <code>BLOB</code>
  80. * value that this <code>Blob</code> object represents. The
  81. * search for <code>pattern</code> begins at position
  82. * <code>start</code>.
  83. * @param pattern the byte array for which to search
  84. * @param start the position at which to begin searching; the
  85. * first position is 1
  86. * @return the position at which the pattern appears, else -1
  87. * @exception SQLException if there is an error accessing the
  88. * <code>BLOB</code>
  89. * @since 1.2
  90. * @see <a href="package-summary.html#2.0 API">What Is in the JDBC 2.0 API</a>
  91. */
  92. long position(byte pattern[], long start) throws SQLException;
  93. /**
  94. * Determines the byte position in the <code>BLOB</code> value
  95. * designated by this <code>Blob</code> object at which
  96. * <code>pattern</code> begins. The search begins at position
  97. * <code>start</code>.
  98. * @param pattern the <code>Blob</code> object designating
  99. * the <code>BLOB</code> value for which to search
  100. * @param start the position in the <code>BLOB</code> value
  101. * at which to begin searching; the first position is 1
  102. * @return the position at which the pattern begins, else -1
  103. * @exception SQLException if there is an error accessing the
  104. * <code>BLOB</code>
  105. * @since 1.2
  106. * @see <a href="package-summary.html#2.0 API">What Is in the JDBC 2.0 API</a>
  107. */
  108. long position(Blob pattern, long start) throws SQLException;
  109. }