求助,Navicat里面显示的数据量和命令行查询出来的数据量不一样。

樱井灬Maria 2016-09-20 10:42:31
RT,我的数据是从Oracle中读取出来的,然后拼出来的SQL在插入到MySQL中的。
二楼贴代码。


...全文
2095 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
姜小果 2018-12-18
  • 打赏
  • 举报
回复
在navicat显示,mycat的数据时,会存在数据量和实际数量不一致这个问题,只要你去查看实际库中数据没有问题就可以,或者你用命令窗口去查询,数据应该是没问题的,我觉得可能是navicat和mycat兼容性还不好,当然这点瑕疵不会影响使用
ACMAIN_CHM 2016-09-20
  • 打赏
  • 举报
回复
显示的统计数据仅供参考,并不准确。
樱井灬Maria 2016-09-20
  • 打赏
  • 举报
回复

package com.common;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;

/**
 * 读取Oracle中的数据 移植到 MySQL中
 * 
 * @author Alex
 *
 */
public class ODataToMData {
	public static void main(String[] args) {
		try {
			for (String tableName : OtoM.tableNames) {
				getDataByOracle(tableName);
			}

		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	public static void getDataByOracle(String table) throws ClassNotFoundException, SQLException {
		Connection connection = OracleDriver.getConn();
		PreparedStatement statement = connection.prepareStatement("SELECT * FROM " + table,
				ResultSet.TYPE_SCROLL_INSENSITIVE , ResultSet.CONCUR_READ_ONLY);
		List<Map<String, String>> list = OtoM.getOracleColumns(table);
		ResultSet resultSet = statement.executeQuery();

		List<String> columns = new ArrayList<>();
		for (Map<String, String> map : list) {
			columns.add(map.get("columnName"));
		}
		List<Map<String, String>> dataList = new ArrayList<>();
		int cursor = 0;
		while (resultSet.next()) {
			cursor++;
			Map<String, String> singleDataMap = new HashMap<>();
			for (String columnName : columns) {
				singleDataMap.put(columnName, resultSet.getString(resultSet.findColumn(columnName)));
			}
			dataList.add(singleDataMap);
			
			if ((cursor!=0&&cursor % 100 == 0)||resultSet.isLast()) {
				System.err.println(cursor+"行,开始提交!");
				insertDataByMySQL(dataList, table);
				dataList.clear();
			}

			// System.out.println(singleDataMap);
			// insertDataByMySQL(singleDataMap, table);
		}
//		System.out.println(cursor);
	}

	public static void insertDataByMySQL(List<Map<String, String>> mapList, String table) throws ClassNotFoundException, SQLException {
		Connection connection = MySQLDriver.getConn();
		StringBuffer buffer = new StringBuffer();
		buffer.append("INSERT INTO ");
		buffer.append("`");
		buffer.append(table);
		buffer.append("` (");

		for (Entry<String, String> entry : mapList.get(0).entrySet()) {
			buffer.append("`");
			buffer.append(entry.getKey());
			buffer.append("`,");
		}
		buffer.delete(buffer.length() - 1, buffer.length());
		buffer.append(") values ");

		for (Map<String, String> map : mapList) {
			buffer.append("(");
			for (Entry<String, String> entry : map.entrySet()) {
				String value = entry.getValue();
				if (value == null || value.equals("null")) {
					value = "NULL";
					buffer.append(value);
				}else{
					buffer.append("'");
					value = value.replace("'", "''");
					buffer.append(value);
					buffer.append("'");	
				}
				buffer.append(",");
			}
			buffer.delete(buffer.length() - 1, buffer.length());
			buffer.append("),");
		}
		buffer.delete(buffer.length() - 1, buffer.length());
		PreparedStatement statement = connection.prepareStatement(buffer.toString());
		int count = statement.executeUpdate();
		System.out.println(count);
	}
}

LongRui888 2016-09-20
  • 打赏
  • 举报
回复
要有精确的值,就用count(*)
樱井灬Maria 2016-09-20
  • 打赏
  • 举报
回复
我只有2000多条数据而已,没有必要用估算,怎么才能用准确的值呢?

56,678

社区成员

发帖
与我相关
我的任务
社区描述
MySQL相关内容讨论专区
社区管理员
  • MySQL
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧