Package java.sql

Examples of java.sql.Blob


     * Test the createBlob method implementation in the Connection interface for
     * in the Network Client
     */
    void t_createBlob_Client() {
        int c;
        Blob blob;
        try {
            Statement s = conn.createStatement();
            s.execute("create table blobtable2(n int,blobcol BLOB)");
            PreparedStatement ps = conn.prepareStatement("insert into blobtable2" +
                    " values(?,?)");
            ps.setInt(1,1000);
            blob = conn.createBlob();
            File file = new File("extin/short.txt");
            FileInputStream is = new FileInputStream(file);
            OutputStream os = blob.setBinaryStream(1);
            c = is.read();
            while(c>0) {
                os.write(c);
                c = is.read();
            }
View Full Code Here


     * the setBlob method in the PreparedStatement interface
     */
    Blob buildAndInsertBlobValue(int n,String filename,Connection conn){
        int c;
        byte [] fromFile = new byte[1024];
        Blob blob=null;
        try {
            blob = conn.createBlob();
            java.io.OutputStream os = blob.setBinaryStream(1);
            buildFilePath(filename);
            File f = new File(filepath + sep + filename);
            InputStream is = getInputStream(f);
            c = is.read(fromFile);
            while(c>0) {
View Full Code Here

            fromFile = new byte[1024];
            Statement s = conn.createStatement();
            s.execute("create table blobtable3(n int)");
            s.execute("alter table blobtable3 add column blobCol BLOB(1M)");
            s.close();
            Blob blob = buildAndInsertBlobValue(0000, "short.txt", conn);
            Blob blob1 = buildAndInsertBlobValue(1000, "aclob.txt", conn);
            Blob blob2 = buildAndInsertBlobValue(2000, "littleclob.txt", conn);
            PreparedStatement ps3 = conn.prepareStatement("select * from " +
                    "blobtable3 where n=1000");
            ResultSet rs3 = ps3.executeQuery();
            rs3.next();
            Blob blob3 = rs3.getBlob(2);
            if(!compareBlob(blob1,blob3)) {
                System.out.println("Difference between the inserted and the " +
                        "queried Blob values");
            }
            PreparedStatement ps4 = conn.prepareStatement("select * from blobtable3");
            ResultSet rs4 = ps4.executeQuery();
            rs4.next();
            Blob blob4 = rs4.getBlob(2);
            if(!compareBlob(blob,blob4)) {
                System.out.println("Difference between the inserted and the " +
                        "queried Blob values");
            }
            rs4.next();
View Full Code Here

    void t_Blob_setMethods_Embedded(Connection conn){
        try {
            Statement s = conn.createStatement();
            ResultSet rs = s.executeQuery("select * from blobtable3");
            rs.next();
            Blob blob = rs.getBlob(2);
            PreparedStatement ps = conn.prepareStatement("insert into blobtable3" +
                    " values(?,?)");
            ps.setInt(1, 3000);
            ps.setBlob(2, blob);
            ps.executeUpdate();
View Full Code Here

   */
  public void setValueFromResultSet(ResultSet resultSet, int colNumber,
                    boolean isNullable)
    throws SQLException, StandardException
  {
        Blob blob = resultSet.getBlob(colNumber);
        if (blob == null)
            setToNull();
        else
            setObject(blob);
  }
View Full Code Here

     * Set the value from an non-null object.
     */
    final void setObject(Object theValue)
        throws StandardException
    {
        Blob vb = (Blob) theValue;
       
        try {
            long vbl = vb.length();
            if (vbl < 0L || vbl > Integer.MAX_VALUE)
                throw this.outOfRange();
           
            setValue(new RawToBinaryFormatStream(
                    vb.getBinaryStream(), (int) vbl),
                    (int) vbl);
           
        } catch (SQLException e) {
            throw dataTypeConversion("DAN-438-tmp");
       }
View Full Code Here

//    else if (name == "java.lang.String") {
//      return String.valueOf(data.toString());
//    }

    if ( data instanceof Blob ) {
      Blob b = (Blob) data;
      try {
        return b.getBytes(1, (int)b.length());
      } catch (SQLException e) {
        throw new RuntimeException(e);
      }
    } else {
      return data;
View Full Code Here

                    while(rs.next())
                    {

                        long messageId = rs.getLong(1);
                        Blob dataAsBlob = rs.getBlob(2);

                        if(messageId > maxId)
                        {
                            maxId = messageId;
                        }

                        byte[] dataAsBytes = dataAsBlob.getBytes(1,(int) dataAsBlob.length());
                        java.nio.ByteBuffer buf = java.nio.ByteBuffer.wrap(dataAsBytes);
                        buf.position(1);
                        buf = buf.slice();
                        MessageMetaDataType type = MessageMetaDataType.values()[dataAsBytes[0]];
                        StorableMessageMetaData metaData = type.getFactory().createMetaData(buf);
View Full Code Here

                try
                {

                    if(rs.next())
                    {
                        Blob dataAsBlob = rs.getBlob(1);

                        byte[] dataAsBytes = dataAsBlob.getBytes(1,(int) dataAsBlob.length());
                        java.nio.ByteBuffer buf = java.nio.ByteBuffer.wrap(dataAsBytes);
                        buf.position(1);
                        buf = buf.slice();
                        MessageMetaDataType type = MessageMetaDataType.values()[dataAsBytes[0]];
                        StorableMessageMetaData metaData = type.getFactory().createMetaData(buf);
View Full Code Here

            int written = 0;

            if (rs.next())
            {

                Blob dataAsBlob = rs.getBlob(1);

                final int size = (int) dataAsBlob.length();
                byte[] dataAsBytes = dataAsBlob.getBytes(1, size);

                if (offset > size)
                {
                    throw new RuntimeException("Offset " + offset + " is greater than message size " + size
                            + " for message id " + messageId + "!");
View Full Code Here

TOP

Related Classes of java.sql.Blob

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.