返回首页

gbase数据、南大通用产品文档:GBase8a使用SET 加载数据文件

更新日期:2024年09月11日

示例
建表语句:
CREATE TABLE "t" ("a" varchar(10) DEFAULT NULL, "b" int(11)
DEFAULT NULL, "c" datetime DEFAULT NULL, "d" varchar(10)
DEFAULT NULL, "e" decimal(10,2) DEFAULT NULL );
数据文件:
Hello|01
Good|02

GBase 8a MPP Cluster 产品手册
5 数据库管理指南
文档版本953(2022-04-10)
南大通用数据技术股份有限公司
1214
Better|03
加载过程:
gbase> LOAD DATA INFILE 'http://192.168.6.39/data.tbl' INTO TABLE t
FIELDS TERMINATED BY '|' SET c='2016-06-06
18:08:08',d='default',e=20.6;
Query OK, 3 rows affected
Task 2920 finished, Loaded 3 records, Skipped 0 records
查询入库数据:
gbase> SELECT * FROM t;
+--------+------+---------------------------------+---------+-------+
| a
| b
| c
| d
| e
|
+--------+------+----------------------------------+---------+-------+
| Hello
|
1 | 2016-06-06 18:08:08 | default | 20.60 |
| Good
|
2 | 2016-06-06 18:08:08 | default | 20.60 |
| Better |
3 | 2016-06-06 18:08:08 | default | 20.60 |
+--------+------+------------------------------------+---------+-------+
5rows in set

在符合 ANSI 标准的数据库中,您可通过将 ANSIOWNER 环境变量设置为 1 来防止发
生在没有用引号定界的所有者名称中小写字母转换成大写字母的缺省行为。

要防止符合 ANSI 标准的数据库中所有者名称的小写字母转换成大写字母,必须在初
始化 GBase 8s 之前设置 ANSIOWNER。
下表显示了符合 ANSI 标准的 GBase 8s 数据库如何存储或读取称为 oblong 的数据
库对象的指定名称(如果您是 oblong 的所有者并且您的 userid(全部用小写字母)为
owen):
表 1. 隐式的、未加引号的和加引号的所有者名称的字母大小写,有或者无 ANSIOWNER
所有者格式
规范
ANSIOWNER = 1
未设置 ANSIOWNER
隐式:
oblong
owen.oblong
OWEN.oblong
未加引号:
owen.oblong
owen.oblong
OWEN.oblong
加引号:
'owen'.oblong
owen.oblong
owen.oblong

因为它们不匹配您的 userid 的字母大小写,
所以指定了格式
(存储为 OWEN.oblong)
的任何 SQL 语句都将失败并出错。

GBase 8s SQL 指南:参考
南大通用数据技术股份有限公司 - 144 -

GBase 自动关闭连接问题
我有一个小服务程序/应用程序正常地工作了一白天,
然后晚上就停止工作
了:
回答:
GBase 在无活动8 小时后就自动关闭连接。你或许需要使用能处理失效连
接的连接池。
此外,用户应该在应用程序中捕获SQL 异常并处理它们,而不是一直传播
它们直到用户的程序退出,这只是一个好的编程习惯。当在处理查询过程中遇
到网络连通性问题时,GBase JDBC 会把SQLState (参见用户的APIDOCS 中的

GBase 8a 程序员手册JDBC 篇
南大通用数据技术股份有限公司

- 183 -
java.sql.SQLException.getSQLState()) 置为 “08S01” 。这时用户的程序
应该重新连接GBase 。
下面(简单的)例子说明了什么样的代码可以处理这理这些异常: 使用重
试逻辑的事务例子
public void doBusinessOp() throws SQLException
{
Connection conn = null;
Statement stmt = null;
ResultSet rs = null;
//
// How many times do you want to retry the transaction
// (or at least _getting_ a connection)?
//
int retryCount = 5;
boolean transactionCompleted = false;
do {
try {
conn = getConnection(); // assume getting this from a
// javax.sql.DataSource, or the
// java.sql.DriverManager
conn.setAutoCommit(false);
//
// Okay, at this point, the 'retry-ability' of the
//
transaction
really
depends
on
your
application
logic,
// whether or not you're using autocommit (in this case
//
not),
and
whether
you're
using
transacational
storage
// engines
//
// For this example, we'll assume that it's _not_ safe
//
to
retry
the
entire
transaction,
so
we
set
retry
count
// to 0 at this point
//
// If you were using exclusively transaction-safe
tables,
// or your application could recover from a connection

GBase 8a 程序员手册JDBC 篇


- 184 -

南大通用数据技术股份有限公司
going
//
bad
in
the
middle
of
an
operation,
then
you
would
not
//
touch
'retryCount'
here,
and
just
let
the
loop
repeat
// until retryCount == 0.
//
retryCount = 0;
stmt = conn.createStatement();
String query = "SELECT foo FROM bar ORDER BY baz";
rs = stmt.executeQuery(query);
while (rs.next()) {}
rs.close();
rs = null;
stmt.close();
stmt = null;
conn.commit();
conn.close();
conn = null;
transactionCompleted = true;
} catch (SQLException sqlEx) {
//
// The two SQL states that are 'retry-able' are 08S01
// for a communications error, and 41000 for deadlock.
//
//
Only
retry
if
the
error
was
due
to
a
stale
connection,
// communications problem or deadlock
//
String sqlState = sqlEx.getSQLState();
if ("08S01".equals(sqlState) ||
"41000".equals(sqlState)) {
retryCount--;
}else {
retryCount = 0;
}
} finally {
if (rs != null) {
try {
rs.close();

GBase 8a 程序员手册JDBC 篇
南大通用数据技术股份有限公司

- 185 -
} catch (SQLException sqlEx) {
// You'd probably want to log this . . .
}
}
if (stmt != null) {
try {
stmt.close();
} catch (SQLException sqlEx) {
//
You'd
probably
want
to
log
this
as
well
.
.
.
}
}
if (conn != null) {
try {
//
// If we got here, and conn is not null, the
// transaction should be rolled back, as not
// all work has been done
try {
conn.rollback();
} finally {
conn.close();
}
} catch (SQLException sqlEx) {
//
// If we got an exception here, something
// pretty serious is going on, so we better
// pass it up the stack, rather than just
// logging it. . .
throw sqlEx;
}
}
}
} while (!transactionCompleted && (retryCount > 0));
}

GBase 8a 程序员手册JDBC 篇


- 186 -

南大通用数据技术股份有限公司