use of java.sql.Blob in project mssql-jdbc by Microsoft.
the class SQLServerResultSet method getBlob.
public Blob getBlob(String colName) throws SQLServerException {
loggerExternal.entering(getClassNameLogging(), "getBlob", colName);
checkClosed();
Blob value = (Blob) getValue(findColumn(colName), JDBCType.BLOB);
loggerExternal.exiting(getClassNameLogging(), "getBlob", value);
activeBlob = value;
return value;
}
use of java.sql.Blob in project mssql-jdbc by Microsoft.
the class SQLServerResultSet method getBlob.
public Blob getBlob(int i) throws SQLServerException {
loggerExternal.entering(getClassNameLogging(), "getBlob", i);
checkClosed();
Blob value = (Blob) getValue(i, JDBCType.BLOB);
loggerExternal.exiting(getClassNameLogging(), "getBlob", value);
activeBlob = value;
return value;
}
use of java.sql.Blob in project mssql-jdbc by Microsoft.
the class SQLServerCallableStatement method getBlob.
public Blob getBlob(int index) throws SQLServerException {
loggerExternal.entering(getClassNameLogging(), "getBlob", index);
checkClosed();
Blob value = (Blob) getValue(index, JDBCType.BLOB);
loggerExternal.exiting(getClassNameLogging(), "getBlob", value);
return value;
}
use of java.sql.Blob in project mssql-jdbc by Microsoft.
the class lobsTest method readBlobStreamAfterClosingRS.
@Test
@DisplayName("readBlobStreamAfterClosingRS")
public void readBlobStreamAfterClosingRS() throws Exception {
String[] types = { "varbinary(max)" };
// create empty table
table = createTable(table, types, false);
int size = 10000;
byte[] data = new byte[size];
ThreadLocalRandom.current().nextBytes(data);
Blob blob = null;
InputStream stream = null;
PreparedStatement ps = conn.prepareStatement("INSERT INTO " + table.getEscapedTableName() + " VALUES(?)");
blob = conn.createBlob();
blob.setBytes(1, data);
ps.setBlob(1, blob);
ps.executeUpdate();
byte[] chunk = new byte[size];
ResultSet rs = stmt.executeQuery("select * from " + table.getEscapedTableName());
rs.next();
blob = rs.getBlob(1);
stream = blob.getBinaryStream();
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
int read = 0;
while ((read = stream.read(chunk)) > 0) buffer.write(chunk, 0, read);
assertEquals(chunk.length, size);
rs.close();
stream = blob.getBinaryStream();
buffer = new ByteArrayOutputStream();
read = 0;
while ((read = stream.read(chunk)) > 0) buffer.write(chunk, 0, read);
assertEquals(chunk.length, size);
if (null != blob)
blob.free();
dropTables(table);
}
use of java.sql.Blob in project mssql-jdbc by Microsoft.
the class lobsTest method readMultipleBlobStreamsThenCloseRS.
@Test
@DisplayName("readMultipleBlobStreamsThenCloseRS")
public void readMultipleBlobStreamsThenCloseRS() throws Exception {
String[] types = { "varbinary(max)" };
table = createTable(table, types, false);
int size = 10000;
byte[] data = new byte[size];
Blob[] blobs = { null, null, null, null, null };
InputStream stream = null;
for (// create 5 blobs
int i = 0; // create 5 blobs
i < 5; // create 5 blobs
i++) {
PreparedStatement ps = conn.prepareStatement("INSERT INTO " + table.getEscapedTableName() + " VALUES(?)");
blobs[i] = conn.createBlob();
ThreadLocalRandom.current().nextBytes(data);
blobs[i].setBytes(1, data);
ps.setBlob(1, blobs[i]);
ps.executeUpdate();
}
byte[] chunk = new byte[size];
ResultSet rs = stmt.executeQuery("select * from " + table.getEscapedTableName());
for (int i = 0; i < 5; i++) {
rs.next();
blobs[i] = rs.getBlob(1);
stream = blobs[i].getBinaryStream();
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
int read = 0;
while ((read = stream.read(chunk)) > 0) buffer.write(chunk, 0, read);
assertEquals(chunk.length, size);
}
rs.close();
for (int i = 0; i < 5; i++) {
stream = blobs[i].getBinaryStream();
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
int read = 0;
while ((read = stream.read(chunk)) > 0) buffer.write(chunk, 0, read);
assertEquals(chunk.length, size);
}
}
Aggregations