java - Inserting and reading blob memsql -


i'm trying insert blob in memsql database.

this source insert, convert blob :

byte[] bytes = rs.getstring(2).getbytes("utf-8"); blob blob = insert.inserttablebinary(bytes); 

this inserttablebinary function :

blob blob = conn.createblob(); blob.setbytes(1, bytes); system.out.println(blob.length()); string sql = "insert binaire(receipt) values(\"" + blob + "\")"; executesql(sql);     return blob; 

at moment blob.lenght equals 1555 when read :

string sql2 = "select * binaire"; statement st = conn.createstatement(); resultset rs2 = st.executequery(sql2); while(rs2.next()) {      blob blob = rs2.getblob(1);     system.out.println(blob.length()); } 

the length 25. strange thing when data in table got : com.mysql.jdbc.blob@6a8bc5d9

so it's doesn't store thing no ? reference object not blob think.

but don't know i'm doing wrong, see lot's of example prepared statement features isn't available in memsql

as joseph suggested, best way issue query use jdbc prepared statements. are supported memsql, , preferred way of executing parametrized queries, because escaping you.

the reason 25-byte string instead of string inserting because blob's tostring method not overridden in java, , when implicitly casted string, returns kind of java pointer instead of content. based on limited knowledge of java alternative joseph suggested in second half of answer (explicitly casting string) result in same behavior. 1 way address byte array blob (blob.getbytes), , passing string

string sql = "insert binaire(receipt) values(\"" + new string(blob.getbytes()) + "\")"; 

this, however, prone sql-injection issues (if blob contains double quote, query either fail, or result in undesirable result), solution prepared statement joseph's answer should used instead.


Comments

Popular posts from this blog

Fail to load namespace Spring Security http://www.springframework.org/security/tags -

sql - MySQL query optimization using coalesce -

unity3d - Unity local avoidance in user created world -