我正在 NetBeans IDE 中设置我的第一个 GridDB Java 应用程序。我在运行应用程序时遇到以下错误:
java.lang.ExceptionInInitializerError 原因:java.lang.RuntimeException:源代码无法编译 - com.toshiba.mwcloud.gs 包不存在 在 griddbconnection.Sample.
(Sample.java:6)
标题截图:
我尝试了以下来自 GridDB 的示例代码:
import java.util.Properties;
import java.util.Date;
import com.toshiba.mwcloud.gs.Collection;
import com.toshiba.mwcloud.gs.GSException;
import com.toshiba.mwcloud.gs.GridStore;
import com.toshiba.mwcloud.gs.GridStoreFactory;
import com.toshiba.mwcloud.gs.Query;
import com.toshiba.mwcloud.gs.RowKey;
import com.toshiba.mwcloud.gs.RowSet;
public class Sample {
static class Person {
@RowKey
String name;
int age;
}
static class HeartRate {
@RowKey
Date ts;
int heartRate;
String activity;
}
public static void main(String[] args) {
Properties props = new Properties();
props.setProperty("notificationAddress", "239.0.0.1");
props.setProperty("notificationPort", "31999");
props.setProperty("clusterName", "defaultCluster");
props.setProperty("user", "admin");
props.setProperty("password", "admin");
try {
GridStore store = GridStoreFactory.getInstance().getGridStore(props);
Collection<String, Person> people = store.putCollection("PEOPLE", Person.class);
Query<Person> query = people.query("select * where name = 'John'");
RowSet<Person> rs = query.fetch(true);
while (rs.hasNext()) {
// Update the searched Row
Person person1 = rs.next();
System.out.println("Name: " + person1.name + " Age: " + person1.age);
}
store.close();
} catch (GSException e) {
System.err.println(e);
}
}
}
我还在我的 NetBeans 项目中添加了最新的 jar 文件 (gridstore-jdbc-5.5.0.jar):
我还将它添加到类路径环境变量中:
您的任何建议将不胜感激!
将以下 jar 放入类路径中
gridstore.jar
您可以在/usr/share/java目录中找到jar