You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafodion.apache.org by li...@apache.org on 2016/11/17 16:19:15 UTC
[2/5] incubator-trafodion git commit: [TRAFODION-2308][JDBC]add test
case for CLOB
[TRAFODION-2308][JDBC]add test case for CLOB
Project: http://git-wip-us.apache.org/repos/asf/incubator-trafodion/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-trafodion/commit/a4a1f1bc
Tree: http://git-wip-us.apache.org/repos/asf/incubator-trafodion/tree/a4a1f1bc
Diff: http://git-wip-us.apache.org/repos/asf/incubator-trafodion/diff/a4a1f1bc
Branch: refs/heads/master
Commit: a4a1f1bc7845ad84bd5e484eb82d36c148b9a04f
Parents: 29bebca
Author: Weiqing Xu <we...@esgyn.cn>
Authored: Mon Oct 31 07:11:18 2016 +0000
Committer: Weiqing Xu <we...@esgyn.cn>
Committed: Mon Oct 31 08:03:44 2016 +0000
----------------------------------------------------------------------
.../java/org/trafodion/jdbc_test/TestClob.java | 95 ++++++++++++++++++++
1 file changed, 95 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/a4a1f1bc/dcs/src/test/jdbc_test/src/test/java/org/trafodion/jdbc_test/TestClob.java
----------------------------------------------------------------------
diff --git a/dcs/src/test/jdbc_test/src/test/java/org/trafodion/jdbc_test/TestClob.java b/dcs/src/test/jdbc_test/src/test/java/org/trafodion/jdbc_test/TestClob.java
new file mode 100644
index 0000000..1d15029
--- /dev/null
+++ b/dcs/src/test/jdbc_test/src/test/java/org/trafodion/jdbc_test/TestClob.java
@@ -0,0 +1,95 @@
+// @@@ START COPYRIGHT @@@
+//
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+//
+// @@@ END COPYRIGHT @@@
+
+import static org.junit.Assert.assertEquals;
+
+import java.sql.Clob;
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.ResultSet;
+import java.sql.Statement;
+
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+public class TestClob {
+ private static final String tableName = "CLOBTEST";
+ private static final String colName = "C1";
+ private static final String strCreateTable = "CREATE TABLE " + Utils.schema + "." + tableName + "(" + colName + " CLOB);";
+ private static final String strDropTable = "DROP TABLE " + Utils.schema + "." + tableName;
+
+ private static Connection _conn = null;
+
+ @BeforeClass
+ public static void doTestSuiteSetup() throws Exception {
+ try {
+ _conn = DriverManager.getConnection(Utils.url, Utils.usr, Utils.pwd);
+ Statement stmt = _conn.createStatement();
+
+ // use CQD to enable CLOB support
+ stmt.execute("CQD TRAF_CLOB_AS_VARCHAR 'OFF'");
+ stmt.execute(strCreateTable);
+ } catch (Exception e) {
+ System.out.println(e.getMessage());
+ e.printStackTrace();
+ }
+ }
+
+ @Test
+ public void readCLOBData() throws Exception {
+ // USE built-in function stringtolob to insert data
+ String data = "this is a CLOB String";
+
+ try (Statement stmt = _conn.createStatement()) {
+ stmt.executeUpdate("INSERT INTO " + Utils.schema + "." + tableName + " (" + colName + ") values (stringtolob('" + data + "'))");
+
+ ResultSet rs = stmt.executeQuery("SELECT * FROM " + Utils.schema + "." + tableName);
+ int rowNum = 0;
+ while (rs.next()) {
+ rowNum++;
+ Clob clob = rs.getClob(colName);
+ assertEquals("clob data ", data, clob.getSubString(1, (int) clob.length()));
+ }
+ assertEquals("Row count read from server", 1, rowNum);
+ } catch (Exception e) {
+ System.out.println(e.getMessage());
+ e.printStackTrace();
+ }
+ }
+
+ @AfterClass
+ public static void cleanTable() throws Exception {
+ try (Statement stmt = _conn.createStatement()) {
+ stmt.execute(strDropTable);
+ } catch (Exception e) {
+ System.out.println(e.getMessage());
+ e.printStackTrace();
+ }
+
+ try {
+ _conn.close();
+ } catch (Exception e) {
+ System.out.println(e.getMessage());
+ e.printStackTrace();
+ }
+ }
+}