Skip to content

Commit a82104b

Browse files
committed
Fix for Bug#105211 (33468860), class java.time.LocalDate cannot be cast
to class java.sql.Date.
1 parent d090238 commit a82104b

File tree

3 files changed

+39
-2
lines changed

3 files changed

+39
-2
lines changed

CHANGES

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33

44
Version 8.0.28
55

6+
- Fix for Bug#105211 (33468860), class java.time.LocalDate cannot be cast to class java.sql.Date.
7+
68
- Fix for Bug#101389 (32089018), GETWARNINGS SHOULD CHECK WARNING COUNT BEFORE SENDING SHOW.
79

810
- Fix for Bug#33488091, Remove all references to xdevapi.useAsyncProtocol from properties and code.

src/main/user-impl/java/com/mysql/cj/jdbc/ServerPreparedStatement.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
import java.io.Reader;
3535
import java.io.UnsupportedEncodingException;
3636
import java.net.URL;
37-
import java.sql.Date;
3837
import java.sql.ParameterMetaData;
3938
import java.sql.SQLException;
4039
import java.sql.Time;
@@ -760,7 +759,7 @@ protected int setOneBatchedParameterSet(java.sql.PreparedStatement batchedStatem
760759
batchedStatement.setTime(batchedParamIndex++, (Time) paramArg[j].value);
761760
break;
762761
case MysqlType.FIELD_TYPE_DATE:
763-
batchedStatement.setDate(batchedParamIndex++, (Date) paramArg[j].value);
762+
batchedStatement.setObject(batchedParamIndex++, paramArg[j].value, MysqlType.DATE);
764763
break;
765764
case MysqlType.FIELD_TYPE_DATETIME:
766765
batchedStatement.setObject(batchedParamIndex++, paramArg[j].value);

src/test/java/testsuite/regression/StatementRegressionTest.java

+36
Original file line numberDiff line numberDiff line change
@@ -11790,4 +11790,40 @@ public void testBlobWithSJIS() throws Exception {
1179011790
}
1179111791
}
1179211792
}
11793+
11794+
/**
11795+
* Test fix for Bug#105211 (33468860), class java.time.LocalDate cannot be cast to class java.sql.Date.
11796+
*
11797+
* @throws Exception
11798+
*/
11799+
@Test
11800+
public void testBug105211() throws Exception {
11801+
createTable("testBug105211", "(dt date)");
11802+
11803+
Properties props = new Properties();
11804+
props.setProperty(PropertyKey.sslMode.getKeyName(), SslMode.DISABLED.name());
11805+
props.setProperty(PropertyKey.allowPublicKeyRetrieval.getKeyName(), "true");
11806+
props.setProperty(PropertyKey.rewriteBatchedStatements.getKeyName(), "true");
11807+
11808+
boolean useSPS = false;
11809+
do {
11810+
props.setProperty(PropertyKey.useServerPrepStmts.getKeyName(), Boolean.toString(useSPS));
11811+
11812+
Connection con = getConnectionWithProps(props);
11813+
this.pstmt = con.prepareStatement("insert into testBug105211(dt) values(?)");
11814+
con.setAutoCommit(false);
11815+
11816+
for (int i = 0; i <= 1000; i++) {
11817+
this.pstmt.setObject(1, LocalDate.now());
11818+
this.pstmt.addBatch();
11819+
if (i % 100 == 0) {
11820+
this.pstmt.executeBatch();
11821+
this.pstmt.clearBatch();
11822+
}
11823+
}
11824+
con.commit();
11825+
11826+
con.close();
11827+
} while (useSPS = !useSPS);
11828+
}
1179311829
}

0 commit comments

Comments
 (0)