0

I am trying to write a record to my GridDB sample database using a small java program. Below shown is my java program:

package gsSample;
import java.util.Arrays;
import java.util.Properties;

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 MyApp2 {
//container schema
static class Person {
    @RowKey String name;
    int age;
}
static class HeartRate {
    @RowKey Date ts;
    int heartRate;
    String activity;
}

public static void main(String[] args) {


//Create a Properties instance to connect to GridDB
Properties props = new Properties();
props.setProperty("notificationAddress", "239.0.0.1");
props.setProperty("notificationPort", "31999");
props.setProperty("clusterName", "defaultCluster");
props.setProperty("user", "administrator");
props.setProperty("password", "password");
GridStore store = GridStoreFactory.getInstance().getGridStore(props);

// Get the container to write records
Collection<String, Person> people = store.putCollection("PEOPLE", Person.class);

//Write a record
HeartRate hr = new HeartRate();
hr.ts = new Date();
hr.heartrate = 60;
hr.activity = "resting";
TimeSeries<HeartRate> heartRate = store.putTimeSeries("HR_"+person1.name,HeartRate.class);
heartRate.put(hr);
}
}

However, when I compile my above java program, I get errors. I am compiling this program in CentOS 7.6 terminal. Please see my commands and the error messages I got on the terminal screen:

-bash-4.2$ export CLASSPATH=${CLASSPATH}:/usr/griddb-4.2.0/bin/gridstore-4.2.0.jar
-bash-4.2$ javac MyApp2.java
MyApp2.java:20: error: cannot find symbol
    @RowKey Date ts;
            ^
  symbol:   class Date
  location: class HeartRate
MyApp2.java:42: error: cannot find symbol
hr.ts = new Date();
            ^
  symbol:   class Date
  location: class MyApp2
MyApp2.java:43: error: cannot find symbol
hr.heartrate = 60;
  ^
  symbol:   variable heartrate
  location: variable hr of type HeartRate
MyApp2.java:45: error: cannot find symbol
TimeSeries<HeartRate> heartRate = store.putTimeSeries("HR_"+person1.name,HeartRate.class);
^
  symbol:   class TimeSeries
  location: class MyApp2
MyApp2.java:45: error: cannot find symbol
TimeSeries<HeartRate> heartRate = store.putTimeSeries("HR_"+person1.name,HeartRate.class);
                                                            ^
  symbol:   variable person1
  location: class MyApp2
5 errors
-bash-4.2$

Would you mind helping me to find out the reason for this error?

dbc
  • 104,963
  • 20
  • 228
  • 340
  • [`Date`](https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/util/Date.html) is in `java.util` so you need to `import java.util.Date;` (or `java.util.*` I suppose). See [How to get the current date and time](https://stackoverflow.com/q/2010284/3744182), which looks like a duplicate. – dbc Nov 13 '21 at 16:07
  • Also, when asking a specific programming question, be sure to tag the question with the language you are using, in this case [tag:java]. That will attract the attention of experts in that language. For guidance on tagging see https://stackoverflow.com/help/tagging. I added the tag for you. – dbc Nov 13 '21 at 16:09

0 Answers0