oracle 插入大文本,字节转浮点数
来源:互联网 发布:灌篮高手全国大赛数据 编辑:程序博客网 时间:2024/06/07 16:48
key: oracle插入超长文本;oracle 插入大数据
参考这篇 写得很好 不再累述
补充
建表语句
create table TESTCLOB( id NUMBER(6), name VARCHAR2(20) not null, CLOBATTR CLOB not null)
package com.grid.test;import java.io.File;import java.io.IOException;import java.io.RandomAccessFile;import java.nio.MappedByteBuffer;import java.nio.channels.FileChannel;import java.nio.channels.FileChannel.MapMode;import java.sql.SQLException;public class ReadFIleData { public static void main(String[] args) { // 读取目录下.data文件 类型 时间 rader_201304.data _ 分隔符 String filePath = "F:/Maobo_Files/微气候细网格城市资源/最终数据/外网data/"; File filepath = new File(filePath); String[] fname = filepath.list(); for (String s : fname) { if (s.endsWith(".data")) { String type = s.split("_")[0]; String datetime = s.split("_")[1]; String dtime = datetime.substring(0, datetime.lastIndexOf(".")); String fpath = filePath + s; try { writeData(type, dtime, fpath); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } } private static void writeData(String type, String datetime, String fpath) throws SQLException, IOException { byte[] bys = null; StringBuffer sb = new StringBuffer(); bys = toByteArray3(fpath); float[] qpe = new float[bys.length / 4]; System.out.println("共计:" + qpe.length); for (int i = 0; i < qpe.length; i++) { float ft = byte2float(bys, i * 4); sb.append(ft < 0 ? 0 : ft); sb.append(","); } System.out.println("sb:" + sb.toString()); // 入库 TestClobIn.doinsert(sb.toString(), type, datetime); } /** * 字节转换为浮点 * * @param b * 字节(至少4个字节) * @param index * 开始位置 * @return */ public static float byte2float(byte[] b, int index) { int fl; fl = b[index + 0]; fl &= 0xff; fl |= ((long) b[index + 1] << 8); fl &= 0xffff; fl |= ((long) b[index + 2] << 16); fl &= 0xffffff; fl |= ((long) b[index + 3] << 24); return Float.intBitsToFloat(fl); } /** * Mapped File way MappedByteBuffer 可以在处理大文件时,提升性能 * * @param filename * @return * @throws IOException */ public static byte[] toByteArray3(String filename) throws IOException { FileChannel fc = null; try { fc = new RandomAccessFile(filename, "r").getChannel(); MappedByteBuffer byteBuffer = fc.map(MapMode.READ_ONLY, 0, fc.size()).load(); System.out.println(" is load: " + byteBuffer.isLoaded()); byte[] result = new byte[(int) fc.size()]; if (byteBuffer.remaining() > 0) { // System.out.println("remain"); byteBuffer.get(result, 0, byteBuffer.remaining()); } return result; } catch (IOException e) { e.printStackTrace(); throw e; } finally { try { fc.close(); } catch (IOException e) { e.printStackTrace(); } } }}//部分源码来自网络,恕不能找到出处了
0 0
- oracle 插入大文本,字节转浮点数
- 浮点数转字节组存储
- 3字节浮点数
- 大浮点数相乘
- 利用oracle long类型字段,插入大文本
- 利用oracle long类型字段,插入大文本
- HDOJ1753 大浮点数相加
- Javascript 限制文本字节数
- (转载)浮点数保存的字节格式
- 浮点数保存的字节格式
- 浮点数与字节数据的转换
- 浮点数与字节数据的转换
- 浮点数与字节数据转换详解
- Java大整数 大浮点数 处理
- 提取文本中任意 浮点数
- [转]深入浅出浮点数
- 浮点数[转]
- 字符串转浮点数
- C语言DAY06 - 循环控制
- 用树莓派打造家庭影院媒体库+硬盘播放机+无人值守下载机(2)
- 文字打字机效果
- C语言DAY07 - 函数
- 页面两列布局高度填满
- oracle 插入大文本,字节转浮点数
- 文件压缩
- [Android测试] AS+Appium+Java+Win 自动化测试之七: 写脚本测试自己的app
- 任务2---标准体重计算器
- LeetCode-Swap Nodes in Pairs
- qt写日志
- 利用ANN来实现简单的深度神经网络
- ListView优化
- spring+mybatis+springMVC详细整合