Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9178509
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T17:34:07+00:00 2026-06-17T17:34:07+00:00

I have a nice MySQL table like this: CREATE TABLE IF NOT EXISTS BLOBTest(Id

  • 0

I have a nice MySQL table like this:

CREATE TABLE IF NOT EXISTS BLOBTest(Id INT PRIMARY KEY AUTO_INCREMENT,

    Data BLOB);

And inside it I have the following:

SELECT HEX(Data) from BLOBTest;

+----------------------------------+
| HEX(Data)                        |
+----------------------------------+
| E764DF04463B55E9E2305934266227A1 |
+----------------------------------+

Translated, I have a table with 1 row and two columns (Id and Data). This row holds byte[] data, the byte[] array stored is the following:
[-25, 100, -33, 4, 70, 59, 85, -23, -30, 48, 89, 52, 38, 98, 39, -95]

How do I make a query to get the entire how?
At first I tried:

SELECT * FROM BLOBTest WHERE Data='[-25, 100, -33, 4, 70, 59, 85, -23, -30, 48, 89, 52, 38, 98, 39, -95]';

However this approach does not work at all, it always returns an empty set. I need to get all the information of that row and all I have is the byte[] value. How do I do it?

Thanks for any help if possible plz.

EDIT:

Here is the code of the java app and what it does.

public Map<Integer, String> queryAuthor(String author) throws Exception{

    //encrypts the name of the author
    byte[] cipheredName = cryptManager.encrypt(keyBytes, 
                author.getBytes());

    //queries db for encrypted name
    pst = con.prepareStatement("SELECT * FROM BLOBTest WHERE DATA='" + cipheredName+"'");

    //builds a map for clients to use with the information from the query. 
    ResultSet rs =  pst.executeQuery();
    Map<Integer, String> result = new HashMap<Integer, String>();
    while (rs.next()) {

        byte[] recoveredBytes = rs.getBytes(2);

        byte[] recoveredName = cryptManager.decrypt(keyBytes, 
                    recoveredBytes);

        result.put(rs.getInt(1), new String(recoveredName));

    }

    return result;
}

The problem is that making:

SELECT * FROM BLOBTest WHERE Data='[-25, 100, -33, 4, 70, 59, 85, -23, -30, 48, 89, 52, 38, 98, 39, -95]';

Returns an empty set, thus making the variable “rs” empty and therefore the returned map is empty. Everyone is sad because I’m a noob and can’t make a simple query like this =(

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T17:34:08+00:00Added an answer on June 17, 2026 at 5:34 pm

    You can send the raw bytes to MySQL as a string literal:

    SELECT * FROM BLOBTest WHERE Data = '????????????????'
    

    (Since not all of your bytes can be represented by printable characters, I haven’t even tried).

    This is particularly easy to do if you pass your data by way of a parameter to a prepared statement (which you really should be doing in any event):

    pst = con.prepareStatement("SELECT * FROM BLOBTest WHERE DATA = ?");
    pst.setBytes(1, cipheredName);
    

    Otherwise you must be careful to ensure that you escape any bytes that MySQL would parse as string termination quotes, as they will otherwise corrupt your query.


    (The following predates the additional information provided in the OP’s edit)

    If that had not been possible, it’d probably have indicated that you shouldn’t be storing your data in a BLOB-type column; for example, 16 TINYINT SIGNED columns might have been more appropriate.

    Even so, there are still possibilities:

    • If you can use Hexadecimal Literal in MariaDB or MySQL , which interprets the hex string to its binary form :

        SELECT * FROM BLOBTest WHERE Data = x'E764DF04463B55E9E2305934266227A1'
      

    See it on sqlfiddle.

    • UNHEX() also does the same thing as described in Hexadecimal Literal above :

      SELECT * FROM BLOBTest WHERE Data = UNHEX('E764DF04463B55E9E2305934266227A1')
      
    • If you can convert each byte to its unsigned value:

        SELECT * FROM BLOBTest WHERE Data = CHAR(
          231,100,223,4,70,59,85,233,226,48,89,52,38,98,39,161
        )
      

    See it on sqlfiddle.

    • Otherwise, you will need to strip the highest order bits as MySQL treats each input to CHAR() as a 4-byte integer:

        SELECT * FROM BLOBTest WHERE Data = CHAR(
          -25 & 0xff,
          100 & 0xff,
          -33 & 0xff,
            4 & 0xff,
           70 & 0xff,
           59 & 0xff,
           85 & 0xff,
          -23 & 0xff,
          -30 & 0xff,
           48 & 0xff,
           89 & 0xff,
           52 & 0xff,
           38 & 0xff,
           98 & 0xff,
           39 & 0xff,
          -95 & 0xff
        )
      

    See it on sqlfiddle.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have one mysql table 'alfa' that will contain the primary key of another
I have a MySQL query that looks like this: UPDATE `Table` SET `Column` =
I have a MySQL table of financial transactions. The table is like so: +----+-----------+--------+--------+---------+---------+
I have html table that get data from mysql. Every 5 seconds I check
I have a mysql table containing messages: id (INT) sender_id (INT) recipient_id (INT) sent_time
have a nice day. I got problem when trying to create an image from
I have a nice DataGridView showing what is basically some kind of log data
I have this nice little MSBuild-based daily build setup that I use on my
I have a MySQL table called invoice_prod : id | qte | price |
I have used mysql to join three tables and print the data in an

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.