基于达梦数据库进行应用开发

配置ODBC

检查gcc

使用命令检查当前系统是否安装gcc,如果没有,那么配置yum源之后,使用yum安装gcc。

rpm -aq | grep gcc

在这里插入图片描述

解压、编译和安装ODBC

tar -zxvf unixODBC-2.3.0.tar.gz
cd unixODBC-2.3.0
./configure --enable-gui=no
make
make install

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

查看ODBC版本

odbc_config --version

odbc_config --odbcini

在这里插入图片描述

odbcinst -j

在这里插入图片描述

cd /usr/local/etc/
vi odbc.ini

在这里插入图片描述

cd /usr/local/etc/
vi odbcinst.ini

在这里插入图片描述

验证是否配置成功

isql dm7
//如果连接失败,可以通过添加参数-v,提示具体错误信息
isql dm7 -v

在这里插入图片描述

达梦JDBC驱动程序Stream的使用

简介

JDBC(Java Database Connectivity)是Java应用程序与数据库的接口规范,旨在让各数据库开发商为Java程序员提供标准的数据库应用程序编程接口(API)。JDBC定义了一个跨数据库、跨平台的通用SQL数据库API。

DM JDBC驱动程序是DM数据库的JDBC驱动程序,它是一个能够支持基本SQL功能的通用应用程序编程接口,支持一般的SQL数据库访问。

通过JDBC驱动程序,用户可以在应用程序中实现对DM数据库的连接与访问,JDBC驱动程序的主要功能包括:
1、建立与DM数据库的连接;
2、转接发送SQL语句到数据库;
3、处理并返回语句执行结果。

本文将主要介绍使用Stream来处理返回的结果集。为了获取大数据量的列,DM JDBC驱动程序提供了四个获取流的方法:
1、getBinaryStream返回只提供数据库原字节而不进行任何转换的流;
2、getAsciiStream返回提供单字节ASCII字符的流;
3、getUnicodeStream返回提供双字节Unicode字符的流;
4、getCharacterStream返回提供双字节Unicode字符的java.io.Reader流。

示例程序

JDBC规范不推荐使用getUnicodeStream方法,其功能可以用getCharacterStream代替。

采用getBinaryStream获取流
// 查询语句 
String sql = "SELECT description FROM production.product WHERE productid=1"; 
// 创建语句对象 
Statement stmt = conn.createStatement(); 
// 执行查询 
ResultSet rs = stmt.executeQuery(sql); 
// 显示结果集 
while (rs.next()) { 
	try { 
		InputStream stream = rs.getBinaryStream("description"); 
		ByteArrayOutputStream baos = new ByteArrayOutputStream(); 
		int num = -1; 
		while ((num = stream.read()) != -1) { 
			baos.write(num); 
		} 
		System.out.println(baos.toString()); 
	} catch (IOException e) { 
		e.printStackTrace(); 
	} 
} 
// 关闭结果集 
rs.close(); 
// 关闭语句 
stmt.close();
采用getAsciiStream获取流
// 查询语句 
String sql = "SELECT description FROM production.product WHERE productid=1"; 
// 创建语句对象 
Statement stmt = conn.createStatement(); 
// 执行查询 
ResultSet rs = stmt.executeQuery(sql); 
// 显示结果集 
while (rs.next()) { 
	try { 
		InputStream stream = rs.getAsciiStream("description"); 
		StringBuffer desc = new StringBuffer(); 
		byte[] b = new byte[1024]; 
		for (int n; (n = stream.read(b)) != -1;) { 
			desc.append(new String(b, 0, n)); 
		} 
		System.out.println(desc.toString()); 
	} catch (IOException e) { 
		e.printStackTrace(); 
	} 
} 
// 关闭结果集 
rs.close(); 
// 关闭语句 
stmt.close();
采用getCharacterStream获取流
// 查询语句 
String sql = "SELECT description FROM production.product WHERE productid=1"; 
// 创建语句对象 
Statement stmt = conn.createStatement(); 
// 执行查询 
ResultSet rs = stmt.executeQuery(sql); 
// 显示结果集 
while (rs.next()) { 
	try { 
		Reader reader = rs.getCharacterStream("description"); 
		BufferedReader br = new BufferedReader(reader); 
		String thisLine; 
		while ((thisLine = br.readLine()) != null) { 
		System.out.println(thisLine); 
	} 
	} catch (IOException e) { 
		e.printStackTrace(); 
	} 
} 
// 关闭结果集 
rs.close(); 
// 关闭语句 
stmt.close();
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值