Training own model in OpenNLP with DB data

I have data in database and need to train own model with this data. All are suggesting try following code.

But can I create model without using sampleStream (without file direct data)? I am new to the openNLP.

public void trainModel() {
    DoccatModel model = null;
    InputStream dataIn = null;
    try{
        InputStreamFactory factory = getInputStreamFactory(new File("D:/training.txt"));
        ObjectStream<String> lineStream = new PlainTextByLineStream(factory, Charset.defaultCharset());
        ObjectStream<DocumentSample> sampleStream = new DocumentSampleStream(lineStream);

        TrainingParameters params = new TrainingParameters();
        params.put(TrainingParameters.ITERATIONS_PARAM, "100");
        params.put(TrainingParameters.CUTOFF_PARAM, "0");

        model = DocumentCategorizerME.train("en", sampleStream, params, factory);
    }catch(Exception e){
        e.printStackTrace();
    }
}