Save to database using marklogic - Java Big Data

Java examples for Big Data:marklogic

Description

Save to database using marklogic

Demo Code



import java.io.FileInputStream;
import java.io.InputStream;

import com.marklogic.client.DatabaseClient;
import com.marklogic.client.DatabaseClientFactory;
import com.marklogic.client.DatabaseClientFactory.Authentication;
import com.marklogic.client.io.InputStreamHandle;
import com.marklogic.client.document.*;

public class LoadTweets {
    public LoadTweets() {
        super();/*from  w  ww  .j av a  2 s . co m*/
    }

    public void queryMarkLogic() {

        try {
            DatabaseClient client = DatabaseClientFactory.newClient(
                    "localhost", 8003, "admin", "marklogic1",
                    Authentication.DIGEST);

            JSONDocumentManager jsonDocMgr = client.newJSONDocumentManager();

            InputStream docStream = new FileInputStream("aa.json");
            InputStreamHandle handle = new InputStreamHandle(docStream);

            jsonDocMgr.write("bb.json", handle);

        } catch (Exception e) {
            e.printStackTrace();
        }

    }

    public static void main(String[] args) {
        LoadTweets markLogicClient = new LoadTweets();
        System.out.println("Query Results:");
        markLogicClient.queryMarkLogic();
    }
}

Related Tutorials