南大通用GBase 8a集群JDBC获取加载行数 Loaded Line,忽略行数skipped Line,任务ID等

GBase 8a集群JDBC获取加载行数 Loaded Line,忽略行数skipped Line,任务ID等

package com.gbase.jdbc;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.sql.Statement;

import com.gbase.jdbc.StatementImpl;

// NEED gbase-connector-java-8.3.81.53-build54.4-bin.jar 
public class TestLoad {

	public static void main(String[] args) throws Exception {
		String URL = "jdbc:gbase://192.168.174.61:5258/testdb?user=gbase&password=gbase20110531&useOldAliasMetadataBehavior=false&failoverEnable=true&hostList=192.168.174.61&gclusterId=vmax";
		// System.out.println(URL);
		Class.forName("com.gbase.jdbc.Driver");

		Connection con = DriverManager.getConnection(URL);

		Statement stat = con.createStatement();
		try {
			int rtn = stat.executeUpdate(
					"LOAD DATA INFILE 'ftp://gbase:gbase@192.168.174.61/zxq/2.txt' into table testdb.t1 fields terminated by ',' max_bad_records 0");
			System.out.println("loaded=" + rtn);// 成功加载的行数
			long skippedLines = ((StatementImpl) (stat)).getSkippedLines();
			System.out.println("Skipped=" + skippedLines);// 成功忽略的行数

			long taskid = ((com.gbase.jdbc.StatementImpl) (stat)).getLoadTaskID();// 任务编号
			System.out.println("LoadTaskId=" + taskid);// 任务编号

			ResultSet rs = stat.executeQuery("show gcluster load logs " + taskid + " limit 0,10");
			ResultSetMetaData rsmd = rs.getMetaData();
			int cols = rsmd.getColumnCount();
			while (rs.next()) {
				for (int i = 1; i <= cols; i++) {
					System.out.println(rsmd.getColumnName(i) + "==>" + rs.getString(i));
				}
			}

		} catch (SQLException ex) {
			ex.printStackTrace();
			System.out.println(ex.getErrorCode());
			System.out.println(ex.getMessage());
			// throw ex;
		}
	}

}

错误数据,可以根据taskId通过SQL获得。请参考

南大通用GBase 8a集群JDBC获取加载行数 Loaded Line,忽略行数skipped Line,任务ID等》有1条评论

评论已关闭。