我试图在一个大查询表中插入数据。
HttpTransport TRANSPORT = new NetHttpTransport();
JsonFactory JSON_FACTORY = new JacksonFactory();
List<String> SCOPES = Arrays
.asList(BigqueryScopes.BIGQUERY);
GoogleCredential credential = null;
AssetManager am = this.getAssets();
InputStream inputStream = null;
try {
inputStream = am.open("hbhjb-8f79f6642470.p12");
} catch (IOException e2) {
e2.printStackTrace();
}
File file = createFileFromInputStream(inputStream, this);
try {
credential = new GoogleCredential.Builder().setTransport(TRANSPORT)
.setJsonFactory(JSON_FACTORY)
.setServiceAccountId("projectnum-*******************[email protected]")
.setServiceAccountScopes(SCOPES)
.setServiceAccountPrivateKeyFromP12File(file)
.build();
} catch (GeneralSecurityException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
Bigquery bigquery = new Bigquery.Builder(TRANSPORT, JSON_FACTORY, credential)
.setApplicationName("BigQuery-Service-Accounts/0.1")
.setHttpRequestInitializer(credential).build();
TableRow data = new TableRow();
data.set("callerNumber", "123456789");
TableDataInsertAllRequest.Rows row = new TableDataInsertAllRequest.Rows();
row.setInsertId(System.currentTimeMillis()+"");
row.setJson(data);
TableDataInsertAllRequest requests = new TableDataInsertAllRequest();
requests.setRows(Arrays.asList(row));
TableDataInsertAllResponse response = null;
try {
response = bigquery.tabledata().insertAll("projectNum", "Data", "CallersData", requests).execute();
Log.d("big query response", response.toString());
} catch (IOException e) {
e.printStackTrace();
}
for (TableDataInsertAllResponse.InsertErrors err: response.getInsertErrors()) {
for (ErrorProto ep: err.getErrors()) {
Log.e("error",ep.getReason() + " : " + ep.getMessage() + " at " + ep.getLocation());
}
}
}
现在问题是我在插入数据时遇到IO异常,即在这一行
response = bigquery.tabledata().insertAll("projectNum", "Data", "CallersData", requests).execute();
我试图从过去两天开始解决这个问题。如果这里有人成功实现了它,请帮助我找到问题。
提前谢谢。
下面是stacktrace
result = {java.io.IOException@830026649024} Method threw 'java.io.IOException' exception.
cause = {java.io.IOException@830026649024} "java.io.IOException"
detailMessage = null
stackState = null
stackTrace = {java.lang.StackTraceElement[30]@830026473856}
suppressedExceptions = {java.util.Collections$EmptyList@830023143656} size = 0
最佳答案
尝试在不同的线程或异步任务中使用相同的代码。如果你还面临任何问题,请告诉我。
关于android - 在Big Query上的表中插入数据时出现IO异常,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/40481371/