Re: ClientPreparedQueryBindings setInt method convert int directly to byte array
Posted by: Filipe Silva
Date: December 22, 2021 05:50AM

Hi Chen Yi,

Yes, this last method would be the preferred way to do this.

But, you are relying on the return from getBytes() which, as you noticed, differs between server-prepared and non-server-prepared statements. While text based protocol returns the bytes from the textual representation of the date (as expected) the binary protocol returns a MySQL internal representation that could change between different server versions... so, it may be a bit more tricky than that to handle this.

Moving forward. You mentioned your concerns with calling rs.getDate(column, calendar.get()); and the fact that the given calendar object gets cloned, but, DATE values and it's Calendar-based getter don't go along very well, right? I mean, date values with time zone conversions always end up causing a lot of troubles. My guess is that you don't really care about the method getDate() itself but the getter methods that take a Calendar argument in general. So, these would be my suggestions:

1. Avoid using getDate(), getTime() and getTimeStamp(), and start using the date/time objects from the java.time package along with setObject()/getObject() with the proper target type. Also set up the connection options 'connectionTimeZone', 'forceConnectionTimeZoneToSession' and 'preserveInstants' to fit your needs.

2. If you absolutely need to use the Calendar-based methods and trusting that you know what you are doing with the Calendar outside of the Connector code, then why don't you provide a dynamically proxies Calendar instance that just replaces the behavior for clone().

3. If you don't want to use dynamic proxies, then why not your own Calendar wrapper that extends the abstract Calendar class, with your own self-returning clone() method?

Anyway, I see that you are working this with the purpose of getting some optimization over the connector code. Are you observing significant performance issues that justify all this? If so, what if you expose your case and maybe we can do some improvements directly inside the connector in future releases?

Options: ReplyQuote




Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.