Android 在大查询的表中插入数据时发生IO异常
我试图在一个大查询的表中插入数据Android 在大查询的表中插入数据时发生IO异常,android,google-app-engine,google-bigquery,google-cloud-platform,Android,Google App Engine,Google Bigquery,Google Cloud Platform,我试图在一个大查询的表中插入数据 HttpTransport TRANSPORT = new NetHttpTransport(); JsonFactory JSON_FACTORY = new JacksonFactory(); List<String> SCOPES = Arrays .asList(BigqueryScopes.BIGQUERY); GoogleCredential credential = null;
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());
}
}
}
我正在努力解决过去两天的问题。如果这里有人成功实施了它,请帮助我找到问题
提前谢谢
下面是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
尝试在不同的线程或异步任务中使用相同的代码。如果您仍然面临任何问题,请告诉我。异常情况说明了什么?@Pentium10我添加了堆栈跟踪..谢谢。代码在我看来没问题。我甚至将它复制并粘贴到我的IDE中(当然更改了项目id等),它工作得很好,即该行成功地流式传输到BigQuery。抱歉,我被难住了。@polleyg是否会因为错误的凭据而导致此错误。我的意思是我对我在此处输入的密钥有疑问。是否会导致此错误。?@polleyg我们是否必须在清单或其他任何地方执行任何spl操作。如果相同的代码在您的端工作,则一定是一个愚蠢的错误..:(我欠你我的命.:DAs bigquery执行网络请求时,需要不同的线程而不是主线程来进行连接。我们不能在主线程上进行网络请求。
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