Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PreparedStatement add objects misbehaviour. #1959

Open
IvanHdzC opened this issue Oct 15, 2020 · 5 comments
Open

PreparedStatement add objects misbehaviour. #1959

IvanHdzC opened this issue Oct 15, 2020 · 5 comments

Comments

@IvanHdzC
Copy link
Contributor

When inserting JsonObjects as SQL objects into a PreparedStatement.

com.telefonica.iot.cygnus.backends.sql.SQLQueryUtils.addJsonValues

It's having trouble with some SQL objects (The ones identified are Timestamp with TZ and functions). The class apparently has no trouble but when connecting to the database the driver asks to casts objects to proper types.

@AlvaroVega AlvaroVega pinned this issue Oct 15, 2020
@fgalan fgalan added this to the release/2.5.0 milestone Oct 15, 2020
@AlvaroVega
Copy link
Member

AlvaroVega commented Oct 16, 2020

@IvanHdzC Currently timestamps are inserted as Strings or using objects? What is the best way?

@IvanHdzC
Copy link
Contributor Author

@IvanHdzC Currently timestamps are inserted as Strings or using objects? What is the best way?

Actually that's the problem. I tried both (setObject and setString) but none of them worked.

There is an specific setTimestamp method, but we don't really know what kind of data is each one of the values to insert.

@AlvaroVega
Copy link
Member

Ideally (jdbc native way) all work should be done by https://github.com/telefonicaid/fiware-cygnus/blob/master/cygnus-common/src/main/java/com/telefonica/iot/cygnus/backends/sql/SQLQueryUtils.java#L351
But currently cygnus is using old cygnus way of compose statement using strings.

@fgalan fgalan removed this from the release/2.5.0 milestone Oct 20, 2020
@AlvaroVega
Copy link
Member

PreparedStatement is still in use in this loop:

for (StringBuffer query : upsertQuerysList) {
PreparedStatement upsertStatement;
currentUpsertQuery = query.toString();
upsertStatement = connection.prepareStatement(query.toString());
// FIXME https://github.com/telefonicaid/fiware-cygnus/issues/1959
upsertStatement.executeUpdate();
upsertQuerys = upsertQuerys + " " + query;
}

But is not really properly used, since each loop iteration is creating a new "preparedStatement" and the current iteration of loop is not using capabilities of a prepared statement (just change one o few value from created statement).

@AlvaroVega AlvaroVega unpinned this issue Sep 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants