Subject | MD5 in VARCHAR |
---|---|
Author | Robert DiFalco |
Post date | 2003-07-02T18:39:09Z |
Is there a character set I can use to store an MD5 into a VARCHAR? I
tried CHARACTER SET NONE and NCHAR but these do not seem to work. I'd
rather not BASE64Encode it if at all possible. Not sure if this is a
driver issue or a data definition problem on my part. Here's the
exceptions I get when I try to write the value:
Defining the column as VARCHAR(16) CHARACTER SET NONE
This one seems to be on writing the bytes into the prepared statement.
java.sql.DataTruncation: Data truncation
at
org.firebirdsql.jdbc.FBStringField.setBytes(FBStringField.java:382)
at
org.firebirdsql.jdbc.FBPreparedStatement.setBytes(FBPreparedStatement.ja
va:170)
at
com.tripwire.space.core.persistence.db.StatementValues.setBytes(Statemen
tValues.java:133)
Defining the column as NCHAR(16)
This one seems to be on executing the statement.
org.firebirdsql.jdbc.FBSQLException: GDS Exception. arithmetic
exception, numeric overflow, or string truncation
Cannot transliterate character between character sets
at
org.firebirdsql.jdbc.FBPreparedStatement.internalExecute(FBPreparedState
ment.java:425)
at
org.firebirdsql.jdbc.FBPreparedStatement.execute(FBPreparedStatement.jav
a:384)
at
com.tripwire.space.core.persistence.db.StatementValues.execute(Statement
Values.java:76)
Basically, I do this:
// Create a 16 byte digest of the data
MessageDigest MD5 = MessageDigest.getInstance( "MD5" );
byte bytes[] = MD5.digest( data );
// put it into a prepared statement
ps.setBytes( bytes );
Fwiw, when I Base64 encode it there are (obviously) no problems.
TIA for any help,
R.
tried CHARACTER SET NONE and NCHAR but these do not seem to work. I'd
rather not BASE64Encode it if at all possible. Not sure if this is a
driver issue or a data definition problem on my part. Here's the
exceptions I get when I try to write the value:
Defining the column as VARCHAR(16) CHARACTER SET NONE
This one seems to be on writing the bytes into the prepared statement.
java.sql.DataTruncation: Data truncation
at
org.firebirdsql.jdbc.FBStringField.setBytes(FBStringField.java:382)
at
org.firebirdsql.jdbc.FBPreparedStatement.setBytes(FBPreparedStatement.ja
va:170)
at
com.tripwire.space.core.persistence.db.StatementValues.setBytes(Statemen
tValues.java:133)
Defining the column as NCHAR(16)
This one seems to be on executing the statement.
org.firebirdsql.jdbc.FBSQLException: GDS Exception. arithmetic
exception, numeric overflow, or string truncation
Cannot transliterate character between character sets
at
org.firebirdsql.jdbc.FBPreparedStatement.internalExecute(FBPreparedState
ment.java:425)
at
org.firebirdsql.jdbc.FBPreparedStatement.execute(FBPreparedStatement.jav
a:384)
at
com.tripwire.space.core.persistence.db.StatementValues.execute(Statement
Values.java:76)
Basically, I do this:
// Create a 16 byte digest of the data
MessageDigest MD5 = MessageDigest.getInstance( "MD5" );
byte bytes[] = MD5.digest( data );
// put it into a prepared statement
ps.setBytes( bytes );
Fwiw, when I Base64 encode it there are (obviously) no problems.
TIA for any help,
R.