12
12
import java .sql .Statement ;
13
13
import java .util .Properties ;
14
14
import net .snowflake .client .category .TestCategoryResultSet ;
15
- import org .junit .After ;
16
15
import org .junit .Before ;
17
16
import org .junit .experimental .categories .Category ;
18
17
@@ -23,79 +22,69 @@ public class ResultSet0IT extends BaseJDBCTest {
23
22
24
23
public Connection init (int injectSocketTimeout ) throws SQLException {
25
24
Connection connection = BaseJDBCTest .getConnection (injectSocketTimeout );
26
-
27
- Statement statement = connection .createStatement ();
28
- statement .execute (
29
- "alter session set "
30
- + "TIMEZONE='America/Los_Angeles',"
31
- + "TIMESTAMP_TYPE_MAPPING='TIMESTAMP_LTZ',"
32
- + "TIMESTAMP_OUTPUT_FORMAT='DY, DD MON YYYY HH24:MI:SS TZHTZM',"
33
- + "TIMESTAMP_TZ_OUTPUT_FORMAT='DY, DD MON YYYY HH24:MI:SS TZHTZM',"
34
- + "TIMESTAMP_LTZ_OUTPUT_FORMAT='DY, DD MON YYYY HH24:MI:SS TZHTZM',"
35
- + "TIMESTAMP_NTZ_OUTPUT_FORMAT='DY, DD MON YYYY HH24:MI:SS TZHTZM'" );
36
- statement .close ();
25
+ try (Statement statement = connection .createStatement ()) {
26
+ statement .execute (
27
+ "alter session set "
28
+ + "TIMEZONE='America/Los_Angeles',"
29
+ + "TIMESTAMP_TYPE_MAPPING='TIMESTAMP_LTZ',"
30
+ + "TIMESTAMP_OUTPUT_FORMAT='DY, DD MON YYYY HH24:MI:SS TZHTZM',"
31
+ + "TIMESTAMP_TZ_OUTPUT_FORMAT='DY, DD MON YYYY HH24:MI:SS TZHTZM',"
32
+ + "TIMESTAMP_LTZ_OUTPUT_FORMAT='DY, DD MON YYYY HH24:MI:SS TZHTZM',"
33
+ + "TIMESTAMP_NTZ_OUTPUT_FORMAT='DY, DD MON YYYY HH24:MI:SS TZHTZM'" );
34
+ }
37
35
return connection ;
38
36
}
39
37
40
38
public Connection init () throws SQLException {
41
39
Connection conn = BaseJDBCTest .getConnection (BaseJDBCTest .DONT_INJECT_SOCKET_TIMEOUT );
42
- Statement stmt = conn .createStatement ();
43
- stmt .execute ("alter session set jdbc_query_result_format = '" + queryResultFormat + "'" );
44
- stmt . close ();
40
+ try ( Statement stmt = conn .createStatement ()) {
41
+ stmt .execute ("alter session set jdbc_query_result_format = '" + queryResultFormat + "'" );
42
+ }
45
43
return conn ;
46
44
}
47
45
48
46
public Connection init (Properties paramProperties ) throws SQLException {
49
47
Connection conn =
50
48
BaseJDBCTest .getConnection (DONT_INJECT_SOCKET_TIMEOUT , paramProperties , false , false );
51
- Statement stmt = conn .createStatement ();
52
- stmt .execute ("alter session set jdbc_query_result_format = '" + queryResultFormat + "'" );
53
- stmt . close ();
49
+ try ( Statement stmt = conn .createStatement ()) {
50
+ stmt .execute ("alter session set jdbc_query_result_format = '" + queryResultFormat + "'" );
51
+ }
54
52
return conn ;
55
53
}
56
54
57
55
@ Before
58
56
public void setUp () throws SQLException {
59
- Connection con = init ();
60
-
61
- // TEST_RS
62
- con .createStatement ().execute ("create or replace table test_rs (colA string)" );
63
- con .createStatement ().execute ("insert into test_rs values('rowOne')" );
64
- con .createStatement ().execute ("insert into test_rs values('rowTwo')" );
65
- con .createStatement ().execute ("insert into test_rs values('rowThree')" );
66
-
67
- // ORDERS_JDBC
68
- Statement statement = con .createStatement ();
69
- statement .execute (
70
- "create or replace table orders_jdbc"
71
- + "(C1 STRING NOT NULL COMMENT 'JDBC', "
72
- + "C2 STRING, C3 STRING, C4 STRING, C5 STRING, C6 STRING, "
73
- + "C7 STRING, C8 STRING, C9 STRING) "
74
- + "stage_file_format = (field_delimiter='|' "
75
- + "error_on_column_count_mismatch=false)" );
76
- // put files
77
- assertTrue (
78
- "Failed to put a file" ,
79
- statement .execute (
80
- "PUT file://" + getFullPathFileInResource (TEST_DATA_FILE ) + " @%orders_jdbc" ));
81
- assertTrue (
82
- "Failed to put a file" ,
83
- statement .execute (
84
- "PUT file://" + getFullPathFileInResource (TEST_DATA_FILE_2 ) + " @%orders_jdbc" ));
85
-
86
- int numRows = statement .executeUpdate ("copy into orders_jdbc" );
87
-
88
- assertEquals ("Unexpected number of rows copied: " + numRows , 73 , numRows );
89
-
90
- con .close ();
91
- }
92
-
93
- @ After
94
- public void tearDown () throws SQLException {
95
- Connection con = init ();
96
- con .createStatement ().execute ("drop table if exists orders_jdbc" );
97
- con .createStatement ().execute ("drop table if exists test_rs" );
98
- con .close ();
57
+ try (Connection con = init ();
58
+ Statement statement = con .createStatement ()) {
59
+
60
+ // TEST_RS
61
+ statement .execute ("create or replace table test_rs (colA string)" );
62
+ statement .execute ("insert into test_rs values('rowOne')" );
63
+ statement .execute ("insert into test_rs values('rowTwo')" );
64
+ statement .execute ("insert into test_rs values('rowThree')" );
65
+
66
+ // ORDERS_JDBC
67
+ statement .execute (
68
+ "create or replace table orders_jdbc"
69
+ + "(C1 STRING NOT NULL COMMENT 'JDBC', "
70
+ + "C2 STRING, C3 STRING, C4 STRING, C5 STRING, C6 STRING, "
71
+ + "C7 STRING, C8 STRING, C9 STRING) "
72
+ + "stage_file_format = (field_delimiter='|' "
73
+ + "error_on_column_count_mismatch=false)" );
74
+ // put files
75
+ assertTrue (
76
+ "Failed to put a file" ,
77
+ statement .execute (
78
+ "PUT file://" + getFullPathFileInResource (TEST_DATA_FILE ) + " @%orders_jdbc" ));
79
+ assertTrue (
80
+ "Failed to put a file" ,
81
+ statement .execute (
82
+ "PUT file://" + getFullPathFileInResource (TEST_DATA_FILE_2 ) + " @%orders_jdbc" ));
83
+
84
+ int numRows = statement .executeUpdate ("copy into orders_jdbc" );
85
+
86
+ assertEquals ("Unexpected number of rows copied: " + numRows , 73 , numRows );
87
+ }
99
88
}
100
89
101
90
ResultSet numberCrossTesting () throws SQLException {
0 commit comments