返回首页

gbase数据、南大通用产品文档:GBase8a

更新日期:2024年09月11日

通过JDBC 执行DDL 和DML 语句
用例executeDDLAndDMLSQLByStatement 方法实现以下功能:

使用Statement 执行DDL 语句创建一个表;

使用Statement 执行DML 语句向表中插入一条数据;

使用Statement 执行DML 语句修改2 中插入的数据。
用例executeDDLAndDMLSQLByPreparedStatement 方法实现以下功能:

使用PreparedStatement 执行DDL 语句创建一个表;

使用PreparedStatement 执行DML 语句向表中插入一条数据;

使用PreparedStatement 执行DML 语句修改2 中插入的数据。
示例如下:
package com.gbase.jdbc.simple;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Statement;

public class ExecuteUpdateSQLByStatement {


private static final String URL =
"jdbc:gbase://192.168.111.95:5258/test?user=sysdba&password=";

/**
* @param args
*/
public static void main(String[] args) {
ExecuteUpdateSQLByStatement executeUpdateSQLByStatement =

GBase 8a 程序员手册JDBC 篇


- 120 -

南大通用数据技术股份有限公司
new ExecuteUpdateSQLByStatement();
executeUpdateSQLByStatement.executeDDLAndDMLSQLByStateme
nt();
executeUpdateSQLByStatement.executeDDLAndDMLSQLByPrepare
dStatement();
}
/**
* 在test 数据库中创建一个名称为
* “user_info”的表,包含三个字段,
* 并向表中插入三条数据。
*/
public void executeDDLAndDMLSQLByStatement () {

Connection conn = null;
Statement stm = null;
try {
Class.forName("com.gbase.jdbc.Driver");
conn = DriverManager.getConnection(URL);
stm = conn.createStatement();

/*
* create table user_info (

user_id int(11) ,

user_Name varchar(50),

user_info varchar(200)

)ENGINE=GsDB DEFAULT CHARSET=utf8
*/
stm.executeUpdate("drop
table
if
exists
`user_info`");
stm.executeUpdate("create table `user_info`
( `user_id` int(11) ,`user_Name` varchar(50),`user_info`
varchar(200))ENGINE=GsDB DEFAULT CHARSET=utf8");
stm.executeUpdate("insert into `user_info`
(`user_id`,`user_name`, `user_info`) values (3,'张五','南大通用
-gbase8d')");
stm.executeUpdate("update `user_info` set `user_name`
= '张五修改' where user_id='3' ");
System.out.println("executeDDLAndDMLSQLByStatement

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

- 121 -
ok");
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
try {
stm.close();
} catch (NullPointerException e) {
} catch (Exception e) {
stm = null;
}
try {
conn.close();
} catch (NullPointerException e) {
} catch (Exception e) {
conn = null;
}
}
}
/**
* 在test 数据库中创建一个名称为
* “user_info”的表,包含三个字段,
* 并向表中插入三条数据。
*/
public void executeDDLAndDMLSQLByPreparedStatement () {

Connection conn = null;
PreparedStatement stm = null;
try {
Class.forName("com.gbase.jdbc.Driver");
conn = DriverManager.getConnection(URL);
stm = conn.prepareStatement("drop table if exists
`user_info`");


GBase 8a 程序员手册JDBC 篇


- 122 -

南大通用数据技术股份有限公司
/*
* create table user_info (

user_id int(11) ,

user_Name varchar(50),

user_info varchar(200)

)ENGINE=GsDB DEFAULT CHARSET=utf8
*/
stm.addBatch("create table `user_info-2` ( `user_id`
int(11) ,`user_Name` varchar(50),`user_info` varchar(200))ENGINE=GsDB
DEFAULT CHARSET=utf8");
stm.executeBatch();
stm
=
conn.prepareStatement("insert
into
`user_info-2`
(`user_id`,`user_name`, `user_info`) values (?,?,?)");
stm.setInt(1, 3);
stm.setString(2, "张五");
stm.setString(3, "南大通用-gbase8d");
stm.executeUpdate();
stm = conn.prepareStatement("update `user_info-2` set
`user_name` = ? where user_id=? ");
stm.setString(1, "张五修改Prepared");
stm.setInt(2, 3);
stm.executeUpdate();

System.out.println("executeDDLAndDMLSQLByPreparedSta
tement ok");
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
try {
stm.close();
} catch (NullPointerException e) {
} catch (Exception e) {
stm = null;

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

- 123 -
}
try {
conn.close();
} catch (NullPointerException e) {
} catch (Exception e) {
stm = null;
}
}
}
}

CPU 降频
部分节点一直性能差,可以查看/proc/cpuinfo 每个核心的MHz 信息是否差距大。
如果差距大,可能是CPU 损坏、或者开启了节能模式、或者CPU 温度高等情况。
比如有些核心的MHz 只有一半,甚至更低,这时需要排查CPU 硬件,关闭CPU
节能模式,改成高性能模式,或者维修、更换。

0 */2 * * * /opt/192.168.146.20/gnode/server/bin/gc_syncpacklog.sh /opt/192.168.