Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to find byte[] in mysql query?
    primarykey
    data
    text
    <p>I have a nice MySQL table like this:</p> <pre><code>CREATE TABLE IF NOT EXISTS BLOBTest(Id INT PRIMARY KEY AUTO_INCREMENT, Data BLOB); </code></pre> <p>And inside it I have the following:</p> <pre><code>SELECT HEX(Data) from BLOBTest; +----------------------------------+ | HEX(Data) | +----------------------------------+ | E764DF04463B55E9E2305934266227A1 | +----------------------------------+ </code></pre> <p>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]</p> <p>How do I make a query to get the entire how? At first I tried:</p> <pre><code>SELECT * FROM BLOBTest WHERE Data='[-25, 100, -33, 4, 70, 59, 85, -23, -30, 48, 89, 52, 38, 98, 39, -95]'; </code></pre> <p>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?</p> <p>Thanks for any help if possible plz.</p> <h1>EDIT:</h1> <p>Here is the code of the java app and what it does. </p> <pre><code>public Map&lt;Integer, String&gt; 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&lt;Integer, String&gt; result = new HashMap&lt;Integer, String&gt;(); while (rs.next()) { byte[] recoveredBytes = rs.getBytes(2); byte[] recoveredName = cryptManager.decrypt(keyBytes, recoveredBytes); result.put(rs.getInt(1), new String(recoveredName)); } return result; } </code></pre> <p>The problem is that making:</p> <pre><code>SELECT * FROM BLOBTest WHERE Data='[-25, 100, -33, 4, 70, 59, 85, -23, -30, 48, 89, 52, 38, 98, 39, -95]'; </code></pre> <p>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 =(</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload