Error : INSERT INTO in dynammic column (CREATE_COLUMN function) with Java Connector.

Hello !

I have discovered dynamics columns few times ago and I would test it with a little java program.

However, I got an error on the CREATE_COLUMN function. I use prepared statement to do it.

This is the query : INSERT INTO maTable (imei, `timestamp`, event, optional_data) VALUES (?, ?, ?, CREATE_COLUMN(?));

Java code is :

//3 first data
MariaDbBlob optionalDataBlob = new MariaDbBlob("'value', '12'".getBytes());
sqlQuery.getPreparedStatement().setBlob(4, optionalDataBlob);

I get the following error : java.sql.SQLSyntaxErrorException: (conn=3548) FUNCTION mydatabase.CREATE_COLUMN does not exist.

But on Dbeaver when I am writing it manually, it works fine. I am probably making something wrong. But what ?

Is it possible to do it with the Java Connector ? If yes, can you tell me how to do it ? I haven't seen explanations on internet.

Thanks a lot for your help, sincerely.

Answer Answered by Axel Dumas in this comment.

Hello !

I have solved the problem... It was a verry silly mistake from me.

Firstly. It's not CREATE_COLUMN but COLUMN_CREATE...it's better. ^^

Secondly. I have used my own method to make SELECT queries, not the UPDATE method.

Thridly (here, it's interesting for others). With prepared statement, you can't make :

In your query : COLUMN_CREATE(?)

MariaDbBlob optionalDataBlob = new MariaDbBlob("'value', '12'".getBytes());
sqlQuery.getPreparedStatement().setBlob(4, optionalDataBlob);

You have to do many "?" to insert your keys and values. So you have to do :

In your query : COLUMN_CREATE(?, ?) //or more "?"

//And you just insert strings.
sqlQuery.getPreparedStatement().setString(4, "value");
sqlQuery.getPreparedStatement().setString(5, "12");

That's all. I hope this mistake will help someone else.

Thanks you, Sincerely.

Comments

Comments loading...
Content reproduced on this site is the property of its respective owners, and this content is not reviewed in advance by MariaDB. The views, information and opinions expressed by this content do not necessarily represent those of MariaDB or any other party.