返回首页

gbase数据、南大通用产品文档:GBase8a程序验证

更新日期:2024年09月11日

编写如下servlet,然后把项目部署到GlassFish 上。
package com.gbase.glassfish;


GBase UP 产品手册 6 应用开发指南
文档版本04(2021-04-21) 南大通用数据技术股份有限公司 1065
import java.io.IOException;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

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 TestServlet extends HttpServlet {

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

/**
* The doGet method of the servlet.

*
* 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 {

Connection conn = null;
ResultSet rs = null;
Statement st = null;
try {
Context ctx = new InitialContext();
DataSource ds = (DataSource) ctx.lookup("gbase2");
conn = ds.getConnection();
st = conn.createStatement();
rs = st.executeQuery("select id,name,age,department from emp");
while(rs.next()){

GBase UP 产品手册 6 应用开发指南
文档版本04(2021-04-21) 南大通用数据技术股份有限公司 1066
System.out.println("员工id:"+rs.getInt(1)+" 员工姓名:"+rs.getString(2)+"
员工年龄:"+rs.getInt(3)+" 员工部门:"+rs.getString(4));
}
} catch (Exception e) {
e.printStackTrace();
}finally{
if(rs != null){
try {
rs.close();
rs = null;
} catch (SQLException e) {
e.printStackTrace();
}
if(st != null){
try {
st.close();
st = null;
} catch (SQLException e) {
e.printStackTrace();
}
if(conn != null){
try {







conn.close();







conn = null;
} catch (SQLException e) {







e.printStackTrace();
}
}
}
}
}
}

/**
* The doPost method of the servlet.

*
* 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

GBase UP 产品手册 6 应用开发指南
文档版本04(2021-04-21) 南大通用数据技术股份有限公司 1067
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doPost(HttpServletRequest request, HttpServletResponse response)


throws ServletException, IOException {

this.doGet(request, response);
}
}
web.xml 文件如下:


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

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

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

http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">

This is the description of my J2EE component
This is the display name of my J2EE component
TestServlet
com.gbase.glassfish.TestServlet



TestServlet
/TestServlet


index.jsp


部署成功后,启动glassfish 服务器,访问如下url:
http://localhost:8088/TestGBase/TestServlet
该测试用例会打印出数据库为test 表为emp 中的内容。

GBase UP 产品手册 6 应用开发指南
文档版本04(2021-04-21) 南大通用数据技术股份有限公司 1068

< 小于
语法
a表达式说明
如果a 小于b,则返回1。如果其中一个操作数是NULL,则返回NULL。
示例
示例1:两个操作数都为数字。
gbase> SELECT 2 < 2 FROM dual;
+-------+
| 2 < 2 |
+-------+
|
0 |
+-------+
1 row in set

连接管理器可以重定向客户机连接请求或充当代理服务器并处理所有客户机/服务器通信。
使用服务级别协议 MODE=REDIRECT 或 MODE=PROXY 属性可指定连接管理器如何处
理客户机连接请求。
图: 在服务级别协议中设置重定向方式


在重定向方式下,连接管理器将相应服务器节点、IP 地址和端口号返回给发出连接请求的
客户机应用程序。然后,客户机应用程序使用连接管理器提供的 IP 地址和端口号来连接
到指定的数据库服务器。
图: 服务级别协议中的 MODE=PROXY

GBase 8s 管理员指南
南大通用数据技术股份有限公司
- 463 -


在代理方式下,连接管理器充当代理服务器,并管理客户机与数据库服务器的通信。当客
户机应用程序无法连接到位于防火墙后面的数据库服务器时,请使用代理方式。要避免连
接管理器成为单个故障点,在使用代理方式时,请配置多个连接管理器实例。