trying storage with JDBC a string digits into Binary cell with no luck .. any suggestions?

32 views
Skip to first unread message

Guy Dviri

unread,
Jun 21, 2018, 5:15:42 AM6/21/18
to Google Cloud SQL discuss
...



preparedStatement.set* ( 1, "3412376179") ; // just a string with alot of digits.//

into  SQL Binary(21) .cell .

I've try all tricks but nothing seems to work , error :

* NOT SPECIFIED *

any quick rescue?

George (Cloud Platform Support)

unread,
Jun 21, 2018, 7:34:23 PM6/21/18
to Google Cloud SQL discuss
Hello Guy, 

How does your statement look like in its entirety? What do you want to accomplish with the prepared statement? 

Java documentation describes method setByte(int parameterIndex, byte x): "Sets the designated parameter to the given Java byte value." that seems to be appropriate in your case. YOu may notice that the second parameter in the set* method is not a string but a byte, so you need to define it accordingly. You may refer to the "Interface PreparedStatement" documentation page

Guy Dviri

unread,
Jun 21, 2018, 8:16:45 PM6/21/18
to Google Cloud SQL discuss
 Hey , let me try to explain the whole scenario  for better understanding.

I have from the user his google plus ID that is huge string something like "13121121111111211233322421"
now i want to convert this huge string into a binary within my SQL table for faster indexing. 
so I made a SQL cell using Binary (21).

now I have try to execute this query :

"select * from connections where connections.left_user = ? and connections.right_user =? ";

the ? are strings with the id.

* NOT SPECIFIED *

now I use JDBC and I try to add to his properties : 

props.setProperty("binaryTransfer","true");

and I try all the combinations I found to try to use the string as binary within the :

preparedStatement.setString(1, .strLeft); // use bytep[[ , binaryStream , everything //

preparedStatement.setString(1, strRight);

resultSet = preparedStatement.executeQuery();

but when I check the log I see those messages about the two values that they are not :* NOT SPECIFIED *

now I change my SQL table left & right back to   'varchar(255)' but I really like to know how to use the binary instead.

thanks alot.













George (Cloud Platform Support)

unread,
Jun 23, 2018, 4:12:30 PM6/23/18
to Google Cloud SQL discuss
How did you convert the huge string to binary? You may find related information on the "2.10 Cast Functions and Operators" page of MySQL manual. 

This discussion group is oriented more towards general opinions, trends and issues of general nature touching the app engine. For coding and programming architecture, you may be better served in a forum such as stackoverflow, where experienced programmers are within reach and ready to help. 

Guy Dviri

unread,
Jun 23, 2018, 4:32:08 PM6/23/18
to Google Cloud SQL discuss
The problem is more  a jdbc driver problem , how do i convert to binary? well as I wrote above i have this string that it's easy to convert to any type , 
but the problem is when i try to set in inside :

preparedStatement.setString(str ) or

any way I've try alot of combination with :

preparedStatement.set* ( str ) and nothing work.

about stack-overflow it's very hard to ask anything.

George (Cloud Platform Support)

unread,
Jun 24, 2018, 5:58:06 PM6/24/18
to Google Cloud SQL discuss
Hello Guy, 

You may follow the examples on the "12.10 Cast Functions and Operators" page, and write something similar to: 

mysql> SET @str = BINARY 'New York';
mysql> SELECT LOWER(@str), LOWER(CONVERT(@str USING utf8mb4));
Reply all
Reply to author
Forward
0 new messages