Mikael wrote:
Hi !
I have a pretty weird problem, I use a Derby 10.3.1.4 with the
ClientDriver and I run the code below:
// Data is a byte[] vector
ByteArrayInputStream is = new ByteArrayInputStream( data);
String sql = "UPDATE MyTable SET FContents=? WHERE FName='" + name
+ "'";
PreparedStatement ps = conn.prepareStatement( sql);
ps.setBinaryStream( 1, is, data.length);
if( ps.executeUpdate() == 0)
{
// it throws an exception here if the data array us larger
then around 32750 bytes!!!
}
Connection is "jdbc:derby://localhost/mydb;create=true;"
java.sql.SQLException: A network protocol error was encountered and
the connection has been terminated: A PROTOCOL Data Stream Syntax
Error was detected. Reason: 0x0. Plaintext connection attempt to an
SSL enabled server?
at
org.apache.derby.client.am.SQLExceptionFactory40.getSQLException(Unknown
Source)
at
org.apache.derby.client.am.SqlException.getSQLException(Unknown Source)
at
org.apache.derby.client.am.PreparedStatement.executeUpdate(Unknown Source)
The table is defined as:
CREATE TABLE MyTable (FName varchar(300) NOT NULL,FContents
BLOB(16M) NOT NULL)
I do not understand why it only works with small BLOB contents, as
soon as I pass 32750 bytes or so the above happens,
when data is 32750 or smaller it works just fine.
Hello Mikal. The error seems related to an SSL enabled server, but it
would seem that you would get that error at connection time, not when
inserting into the table. I tried the following program just starting
network server normally java org.apache.derby.drda.NetworkServerControl
start and it seemed to run ok. Can you tell me how to modify this
program or the way I started the server to reproduce your error?
Thanks
Kathey
import java.sql.*;
import java.io.*;
public class TestBlob {
public static void main(String args[]) throws Exception {
Class.forName("org.apache.derby.jdbc.ClientDriver").newInstance();
Connection conn =
DriverManager.getConnection("jdbc:derby://localhost:1527/wombat;create=true");
Statement s = conn.createStatement();
try {
s.executeUpdate("drop table MyTable");
} catch (SQLException se) {}
s.executeUpdate("create table MyTable (Contents BLOB(2G))");
s.executeUpdate("insert into MyTable VALUES NULL");
byte[] data = new byte[40000];
for (int i = 0; i < 40000; i++)
data[i] = 'a';
ByteArrayInputStream is = new ByteArrayInputStream( data);
String sql = "UPDATE MyTable SET Contents=?";
PreparedStatement ps = conn.prepareStatement( sql);
ps.setBinaryStream( 1, is, data.length);
ps.executeUpdate();
ps.close();
conn.close();
}
}