我正在尝试在大查询的表格中插入数据。我跟着几个文档,我的最终代码看起来像
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-*******************3ee3130770087ceab09a482173@developer.gserviceaccount.com")
.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();
我正在尝试解决这个问题。过去2天。如果有人成功实施,请帮助我找到问题。
提前致谢。
以下是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
答案 0 :(得分:1)
尝试在不同的线程或Asynctask中使用相同的代码。如果您仍然遇到任何问题,请告诉我。