diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/IOBuffer.java b/src/main/java/com/microsoft/sqlserver/jdbc/IOBuffer.java index 70b5bc74b5..e5e175b9e9 100644 --- a/src/main/java/com/microsoft/sqlserver/jdbc/IOBuffer.java +++ b/src/main/java/com/microsoft/sqlserver/jdbc/IOBuffer.java @@ -1056,7 +1056,7 @@ private void writeInternal(byte[] b, int off, int len) throws IOException { private final class ProxyInputStream extends InputStream { private InputStream filteredStream; - private final transient Lock proxyInputStreamLock = new ReentrantLock(); + private final Lock proxyInputStreamLock = new ReentrantLock(); /** * Bytes that have been read by a poll(s). @@ -3854,10 +3854,8 @@ void writeTime(java.sql.Timestamp value, int scale) throws SQLServerException { void writeTime(java.sql.Timestamp value, int scale, Calendar cal) throws SQLServerException { GregorianCalendar calendar = initializeCalender(TimeZone.getDefault()); - long utcMillis; // Value to which the calendar is to be set (in milliseconds 1/1/1970 00:00:00 GMT) - int subSecondNanos; - utcMillis = value.getTime(); - subSecondNanos = value.getNanos(); + long utcMillis = value.getTime(); // Value to which the calendar is to be set (in milliseconds 1/1/1970 00:00:00 GMT) + int subSecondNanos = value.getNanos(); // Load the calendar with the desired value calendar.setTimeInMillis(utcMillis); diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerBulkCopy.java b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerBulkCopy.java index 877405e6ae..73521adea2 100644 --- a/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerBulkCopy.java +++ b/src/main/java/com/microsoft/sqlserver/jdbc/SQLServerBulkCopy.java @@ -2480,13 +2480,10 @@ else if (4 >= bulkScale) tdsWriter.writeByte((byte) 0x07); else tdsWriter.writeByte((byte) 0x08); - Timestamp ts = java.sql.Timestamp.valueOf(colValue.toString()); + Timestamp ts = (Timestamp) colValue; tdsWriter.writeTime(ts, bulkScale, cal); // Send only the date part tdsWriter.writeDate(ts.getTime(), cal); - //tdsWriter.writeRPCDateTime2(name, - // timestampNormalizedCalendar(calendar, javaType, conn.baseYear()), - // subSecondNanos, TDS.MAX_FRACTIONAL_SECONDS_SCALE, isOutParam); } } break; diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/BatchExecutionTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/BatchExecutionTest.java index 9a755cd3fd..3384f278cb 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/BatchExecutionTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/unit/statement/BatchExecutionTest.java @@ -63,7 +63,7 @@ public class BatchExecutionTest extends AbstractTest { private static String timestampTable1 = AbstractSQLGenerator .escapeIdentifier(RandomUtil.getIdentifier("timestamptable1")); private static String timestampTable2 = AbstractSQLGenerator - .escapeIdentifier(RandomUtil.getIdentifier("timestampTableBatchInsert2")); + .escapeIdentifier(RandomUtil.getIdentifier("timestamptable2")); /** * This tests the updateCount when the error query does cause a SQL state HY008. @@ -142,28 +142,27 @@ public void testValidTimezoneForTimestampBatchInsertWithBulkCopy() throws Except } // Compare Timestamp values inserted, should be the same - try (Connection con = DriverManager.getConnection(connectionString); Statement stmt = con.createStatement()) { - try (ResultSet rs = stmt.executeQuery("SELECT * FROM " + timestampTable1)) { - Timestamp ts0; - Timestamp ts1; - Time t0; - Time t1; - Date d0; - Date d1; - - rs.next(); - ts0 = rs.getTimestamp(1); - t0 = rs.getTime(1); - d0 = rs.getDate(1); - rs.next(); - ts1 = rs.getTimestamp(1); - t1 = rs.getTime(1); - d1 = rs.getDate(1); - - assertEquals(ts0, ts1); - assertEquals(t0, t1); - assertEquals(d0, d1); - } + try (Connection con = DriverManager.getConnection(connectionString); Statement stmt = con.createStatement(); + ResultSet rs = stmt.executeQuery("SELECT * FROM " + timestampTable1)) { + Timestamp ts0; + Timestamp ts1; + Time t0; + Time t1; + Date d0; + Date d1; + + rs.next(); + ts0 = rs.getTimestamp(1); + t0 = rs.getTime(1); + d0 = rs.getDate(1); + rs.next(); + ts1 = rs.getTimestamp(1); + t1 = rs.getTime(1); + d1 = rs.getDate(1); + + assertEquals(ts0, ts1); + assertEquals(t0, t1); + assertEquals(d0, d1); } } @@ -204,29 +203,28 @@ public void testValidTimezonesDstTimestampBatchInsertWithBulkCopy() throws Excep } // Compare Timestamp values inserted, should be the same - try (Connection con = DriverManager.getConnection(connectionString); Statement stmt = con.createStatement()) { - try (ResultSet rs = stmt.executeQuery("SELECT * FROM " + timestampTable1)) { - Timestamp ts0; - Timestamp ts1; - Time t0; - Time t1; - Date d0; - Date d1; - - rs.next(); - ts0 = rs.getTimestamp(1); - t0 = rs.getTime(1); - d0 = rs.getDate(1); - rs.next(); - ts1 = rs.getTimestamp(1); - t1 = rs.getTime(1); - d1 = rs.getDate(1); - - String failureMsg = "Failed for time zone: " + tzId; - assertEquals(ts0, ts1, failureMsg); - assertEquals(t0, t1, failureMsg); - assertEquals(d0, d1, failureMsg); - } + try (Connection con = DriverManager.getConnection(connectionString); Statement stmt = con.createStatement(); + ResultSet rs = stmt.executeQuery("SELECT * FROM " + timestampTable1)) { + Timestamp ts0; + Timestamp ts1; + Time t0; + Time t1; + Date d0; + Date d1; + + rs.next(); + ts0 = rs.getTimestamp(1); + t0 = rs.getTime(1); + d0 = rs.getDate(1); + rs.next(); + ts1 = rs.getTimestamp(1); + t1 = rs.getTime(1); + d1 = rs.getDate(1); + + String failureMsg = "Failed for time zone: " + tzId; + assertEquals(ts0, ts1, failureMsg); + assertEquals(t0, t1, failureMsg); + assertEquals(d0, d1, failureMsg); } } } @@ -264,28 +262,27 @@ public void testBatchInsertTimestampNoTimezoneDoubleConversion() throws Exceptio } // Compare Timestamp values inserted, should be the same - try (Connection con = DriverManager.getConnection(connectionString); Statement stmt = con.createStatement()) { - try (ResultSet rs = stmt.executeQuery("SELECT * FROM " + timestampTable2)) { - Timestamp ts0; - Timestamp ts1; - Time t0; - Time t1; - Date d0; - Date d1; - - rs.next(); - ts0 = rs.getTimestamp(1); - t0 = rs.getTime(1); - d0 = rs.getDate(1); - rs.next(); - ts1 = rs.getTimestamp(1); - t1 = rs.getTime(1); - d1 = rs.getDate(1); - - assertEquals(ts0, ts1); - assertEquals(t0, t1); - assertEquals(d0, d1); - } + try (Connection con = DriverManager.getConnection(connectionString); Statement stmt = con.createStatement(); + ResultSet rs = stmt.executeQuery("SELECT * FROM " + timestampTable2)) { + Timestamp ts0; + Timestamp ts1; + Time t0; + Time t1; + Date d0; + Date d1; + + rs.next(); + ts0 = rs.getTimestamp(1); + t0 = rs.getTime(1); + d0 = rs.getDate(1); + rs.next(); + ts1 = rs.getTimestamp(1); + t1 = rs.getTime(1); + d1 = rs.getDate(1); + + assertEquals(ts0, ts1); + assertEquals(t0, t1); + assertEquals(d0, d1); } }