I am working on an app that needs to be able to download BLOBs from oracle. This is the code that I currently have:
public static void getBLOB(Connection c)
{
int recNum = Integer.parseInt(readEntry("Enter Record Number: "
);
//byte[] allBytesInBlob = new byte[0];
//byte[] bytes = new byte[0];
int len = -1;
Blob aBlob = null;
try
{ // Prepare a Statement:
PreparedStatement stmnt = c.prepareStatement("select audiomsg from call where callerid like"+recNum+"'"
;
// Execute
ResultSet rs = stmnt.executeQuery();
aBlob = rs.getBlob(1);
while(rs.next())
{
try
{
System.out.println("TRY"
;
// Get as a BLOB
aBlob = rs.getBlob(1);
System.out.println("BTEST: "+aBlob.length());
byte[] allBytesInBlob = aBlob.getBytes(1, (int) aBlob.length());
len = allBytesInBlob.length;
}
catch(Exception ex)
{
System.out.println("CATCH"
;
// The driver could not handle this as a BLOB...
// Fallback to default (and slower) byte[] handling
byte[] bytes = rs.getBytes(1);
len = bytes.length;
}
}
// Close resources
rs.close();
stmnt.close();
}
catch(Exception ex)
{
//this.log("Error when trying to read BLOB: " + ex);
}
//System.out.println("byte array length is: (abib) "+allBytesInBlob.length+" bytes[]: "+bytes.length);
try {
byte[] myBytes = aBlob.getBytes(1, (int) aBlob.length());
}
catch (SQLException ex1) {
System.out.println("ERROR: "+ex1);
}
System.out.println("len: "+len);
}
This code compiles but doesn't seem to do anything. Does anyone have any experience with utalizing BLOBs from oracle. Some sample code and explainations would be very helpful.
Thank You.
public static void getBLOB(Connection c)
{
int recNum = Integer.parseInt(readEntry("Enter Record Number: "
//byte[] allBytesInBlob = new byte[0];
//byte[] bytes = new byte[0];
int len = -1;
Blob aBlob = null;
try
{ // Prepare a Statement:
PreparedStatement stmnt = c.prepareStatement("select audiomsg from call where callerid like"+recNum+"'"
// Execute
ResultSet rs = stmnt.executeQuery();
aBlob = rs.getBlob(1);
while(rs.next())
{
try
{
System.out.println("TRY"
// Get as a BLOB
aBlob = rs.getBlob(1);
System.out.println("BTEST: "+aBlob.length());
byte[] allBytesInBlob = aBlob.getBytes(1, (int) aBlob.length());
len = allBytesInBlob.length;
}
catch(Exception ex)
{
System.out.println("CATCH"
// The driver could not handle this as a BLOB...
// Fallback to default (and slower) byte[] handling
byte[] bytes = rs.getBytes(1);
len = bytes.length;
}
}
// Close resources
rs.close();
stmnt.close();
}
catch(Exception ex)
{
//this.log("Error when trying to read BLOB: " + ex);
}
//System.out.println("byte array length is: (abib) "+allBytesInBlob.length+" bytes[]: "+bytes.length);
try {
byte[] myBytes = aBlob.getBytes(1, (int) aBlob.length());
}
catch (SQLException ex1) {
System.out.println("ERROR: "+ex1);
}
System.out.println("len: "+len);
}
This code compiles but doesn't seem to do anything. Does anyone have any experience with utalizing BLOBs from oracle. Some sample code and explainations would be very helpful.
Thank You.