返回首页

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

更新日期:2024年09月11日

程序验证
编写如下Serverlet,到处war 包,部署到websphere 上。
package com.gbase.test;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.HashMap;
import java.util.Map;

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

- 75 -

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.sql.DataSource;

public class WebshpereJNDITest extends HttpServlet {

/**
*
*/
private static final long serialVersionUID =
8570136076952105578L;

/**
* Constructor of the object.
*/
public WebshpereJNDITest() {
super();
}

/**
* Destruction of the servlet.

*/
public void destroy() {
super.destroy(); // Just puts "destroy" string in log
// Put your code here
}

/**
* The doGet method of the servlet.

*

GBase 8a 程序员手册JDBC 篇


- 76 -

南大通用数据技术股份有限公司
*
This
method
is
called
when
a
form
has
its
tag
value
method
equals
to get.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {

response.setContentType("text/html");
PrintWriter out = response.getWriter();

Connection conn = null;
Statement stmt = null;
ResultSet rs = null;
try {
System.out.println("come");
Context initCtx = new InitialContext();
// 获得连接池
DataSource ds = (DataSource) initCtx





.lookup("ds/8acluster");
Map cacheMap = new HashMap();
// 创建连接
conn = ds.getConnection();

System.out.println(conn.getMetaData().getURL());
if (conn != null) {
out.println("The Gbase connection is ok!!");
System.out.println("ok");
} else {
out.println("The Gbase connection occur error");
System.out.println("error");
}
// 使用连接创建Statement 对象执行SQL 语句

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

- 77 -
Statement st = conn.createStatement();
ResultSet rs1 = st


.executeQuery("select * from information_schema.TABLES");
ResultSetMetaData rsm = rs1.getMetaData();
// 获得执行结果,输出结果
while (rs1.next()) {
for (int i = 0; i < rsm.getColumnCount(); i++) {
out.println(rsm.getColumnName(i + 1)+ "= "+
rs1.getString(i + 1));
out.println("
");
}
out.println("+++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++
");
}
} catch (Exception e) {
e.printStackTrace();
out.println(e);
} finally {
out.flush();
out.close();
if (conn == null) {
try {
conn.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

}
}
}

public String getCurrentIp(String url) {
return url.substring(url.indexOf("currentIp"),
url.length());
}
/**
* The doPost method of the servlet.


GBase 8a 程序员手册JDBC 篇


- 78 -

南大通用数据技术股份有限公司
*
*
This
method
is
called
when
a
form
has
its
tag
value
method
equals
to post.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doPost(HttpServletRequest request,
HttpServletResponse response)



throws ServletException, IOException {

doGet(request, response);
}

/**
* Initialization of the servlet.

*
* @throws ServletException if an error occurs
*/
public void init() throws ServletException {
// Put your code here
}
}

web.xml 配置如下:


xmlns="http://java.sun.com/xml/ns/j2ee"

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee

http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">


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

- 79 -
websphereJNDITest
com.gbase.test.WebshpereJNDITestass>



websphereJNDITest
/websphereJNDITest


index.jsp


在部署测试war 包是 “上下文根”使用 “/JNDITest”
部署成功后使用如下URL 访问:
http://localhost:9082/JDNITest/websphereJNDITest
该测试用例会打印出目标数据库中information_schema.TABLES 的内容。

GBA-02DD-0025
错误码
错误标识
错误信息
GBA-02DD-002
5

The
user
named
gbase
can't
be
operated.
错误出现原因
基于目前的设计,不允许对gbase 用户进行更改【会在合适的时机去掉此限制】
分析与建议
gbase 作为内建用户,
暂时不允许对其进行操作,
因此检查SQL 是否正要对gbase
用户做更改。

删除Hash 索引
使用“删除索引”功能,您可以删除Hash 索引。
在“对象资源管理器”中,右键单击表节点下的索引节点中的您要删除的
索引,选择菜单中的“删除”菜单项,如下图所示:

GBase 8a MPP Cluster 管理工具手册

- 72 -

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

图 7-46 删除索引菜单项
选择“删除”菜单项,将删除掉您所选择的索引。