Mailing List
Home
Forum Home
MySQL General - General MySQL discussion
MySQL++ - Programming with the C++ API to MySQL
MaxDB - Everything about MaxDB, formerly known as SAP DB
ODBC - ODBC with the MySQL Connector/ODBC driver
MySQL on Win32 - Runing MySQL on Windows 9x/Me/NT/2000/XP
Java Help - Mostly related to the MySQL Connector/J driver
Perl - Perl support for MySQL with DBI and DBD::mysql
GUI - MySQL GUI Tools
Announcement
Subjects
Subject: mysql openssl Question
ERROR 1045: Access denied for user: 'root@localhost ' (Using
password: NO)
Update one field with more fields from another table
Subject: Getting Identity after INSERT
ERROR 2002: Can 't connect to local MySQL server through socket
mysql test 4 1 fails with the gis test
Subject: MySQL Cluster Software
Downgrade Mysql from 4 to 3 23
Mysql 4 0 Oracle Stored Procedure Trigger Conversion
Can 't access mysql after kernel upgrade
Executing MySQL Commands From Within C Program
Comparing and writing out BLOBS
Subject: Re: Preventing Duplicate Entries
FULLTEXT query format question
Strange behavior, Table Level Permission
Does the binary log enabling affect the MySQL performances?
mysql:it 's a db not a dbms how it 's possible?!
mysql have same function mthod as Oracle decode()
 
Subject: getObject() autoDeserialize question

Subject: getObject() autoDeserialize question

2007-11-06       - By Pavel B. Milovantsev

 Back
Hello, not sure that this is a bug, so prefer to ask it at the maillist.

   As I see the only backport at 3.1.11 which consider blobs
(http://bugs.mysql.com/bug.php?id=13277), but I don't understand why it
provoke change at ResultSet(Impl).java:getObject():

from:
if ((data[0] == -84) && (data[1] == -19)) {
   // Serialized object?
   ....
}

to:
if ((data[0] == -84) && (data[1] == -19)) {
   // Serialized object?
   ....
} else {
   return getString(columnIndex);
}


   This simple code works on mysql connector/J version 3.1.10, and
fails at version 5.1.5 with java.lang.ClassCastException:
java.lang.String cannot be cast to [B

import java.sql.*;

public class Main {
  public static void main(final String[] args) throws Exception {
    byte[] byteArrayWrite = new byte[Math.abs(Byte.MIN_VALUE) +
Math.abs(Byte.MIN_VALUE) + 1];
    for (int b = 0; b < Math.abs(Byte.MIN_VALUE) +
Math.abs(Byte.MAX_VALUE) + 1; b++)
      byteArrayWrite[b] = (byte)(b + Byte.MIN_VALUE);

    Class.forName("com.mysql.jdbc.Driver").newInstance();
    Connection conn =
DriverManager.getConnection("jdbc:mysql://localhost/sw2_std?user=root&password
=XXX&useUnicode=true&characterEncoding=UTF-8 (See http://UTF-8.ora-code.com)&zeroDateTimeBehavior=convertToNull
&autoDeserialize=true&jdbcCompliantTruncation=false");

    PreparedStatement stmt  = conn.prepareStatement("insert into
testblob(blob_field) values(?)");
    stmt.setObject(1, byteArrayWrite);
    stmt.executeUpdate();

    stmt  = conn.prepareStatement("select blob_field from testblob");
    ResultSet rs = stmt.executeQuery();
    if (rs.next()) {
      final byte[] byteArrayRead = (byte[]) rs.getObject(1);

      // Make sure original and read content are equal
      assert byteArrayRead.length == byteArrayWrite.length;
      for (int byteArrayIdx = 0; byteArrayIdx < byteArrayRead.length;
byteArrayIdx++)
        assert byteArrayRead[byteArrayIdx] == byteArrayWrite[byteArrayIdx];
    }
  }
}


> mysql> show create table testblob;
> +-- ---- --+-- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- --
-- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- --
-- ---- ---- ---- ---- ---- ---- ---- --+
> | Table    | Create Table                                                    
                                                                               
                                       |
> +-- ---- --+-- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- --
-- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- --
-- ---- ---- ---- ---- ---- ---- ---- --+
> | testblob | CREATE TABLE `testblob` (
>   `pk_field` bigint(20) NOT NULL auto_increment,
>   `blob_field` mediumblob,
>   PRIMARY KEY  (`pk_field`)
> ) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8 |
> +-- ---- --+-- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- --
-- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- --
-- ---- ---- ---- ---- ---- ---- ---- --+
> 1 row in set (0.00 sec)
--
Pavel B. Milovantsev <pav@(protected)>
SupportWizard


--
MySQL Java Mailing List
For list archives: http://lists.mysql.com/java
To unsubscribe:    http://lists.mysql.com/java?unsub=mysql@(protected)