我正在使用一个包含 Oracle NoSQL 数据库的Docker容器。我正在尝试使用 Java 程序创建一个表并填写一些记录。
我试图存储的数据是来自存储在 JSON 文件中的推文的元数据,但为了简单起见,我准备了一个带有更基本示例的演示。在这个演示中,我将尝试创建并填充一个只有 4 个字段的表和一个非常简单的 JSON 文件,其中包含要存储的数据。这是代码:
private static void demo(KVStore kvstore, String file2load) {
//Creating the table
String query = "CREATE TABLE Carros (plate STRING, brand STRING, owner STRING, km NUMBER, primary key (plate))";
try {
kvstore.executeSync(query);
} catch (IllegalArgumentException e) {
System.out.println("Invalid statement:\n" + e.getMessage());
} catch (FaultException e) { //ATENTION HERE <-
System.out.println("Statement couldn't be executed, please retry: " + e);
}
System.out.println("Table created");
//Fill up the table
populateTable(kvstore, file2load);
System.exit(0);
}
您在上面看到的是 main 中调用的方法。现在,我还将在此处保留 populateTable() 方法,尽管它工作正常:
private static void populateTable(KVStore kvstore, String file2load) {
TableAPI tableH = kvstore.getTableAPI();
Table myTable = tableH.getTable("Carros");
BufferedReader br = null;
FileReader fr = null;
try {
String jObj = "";
String currLine;
int tCount = 0;
boolean buildObj = false;
boolean beganParsing = false;
fr = new FileReader(file2load);
br = new BufferedReader(fr);
while ((currLine = br.readLine()) != null) {
tCount += countParens(currLine, '{');
if ((currLine = br.readLine()) == "\n") {
continue;
}
if (tCount > 0) {
buildObj = true;
beganParsing = true;
}
//Anadimos la linea leida
if (buildObj) {
jObj += currLine;
}
tCount -= countParens(currLine, '}');
if (tCount < 1)
buildObj = false;
if (beganParsing && !buildObj) {
Row row = myTable.createRowFromJson(jObj, false);
tableH.put(row, null, null);
jObj = "";
}
}//While
} catch (FileNotFoundException fnfe) {
System.out.println("File not found: " + fnfe);
System.exit(-1);
} catch (IOException ioe) {
System.out.println("IOException: " + ioe);
System.exit(-1);
} finally {
try {
if (br != null)
br.close();
if (fr != null)
fr.close();
} catch (IOException iox) {
System.out.println("IOException on close: " + iox);
}
}
}//populateTable
所以我的问题是,每次我执行这个程序时,它都会毫无问题地到达执行结束,因为我使用了 try-catch 块,但是,它不会创建或填充任何表。我收到的信息是:
语句无法执行,请重试:oracle.kv.FaultException: no such object in table (12.1.4.3.11) (18.3.10) 故障类名:oracle.kv.impl.admin.AdminFaultException
我已经在上面的第一段代码中注释了导致这种情况的异常。由于我没有发现任何成功搜索此问题,我删除了 try-catch 以获得更详细的错误跟踪:
java:111) 在 oracle.kv.impl.client.admin.DdlStatementExecutor.executeDdl(DdlStatementExecutor.java:363) ... 还有 6 天我一直在寻找为什么这不起作用。此外,我什至无法在 kv 终端上执行操作,例如
execute "CREATE TABLE ....."
因为这也行不通。有任何想法吗?先感谢您。