dcsimg
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: Newbee Java and Mongo Questions.

  1. #1
    Join Date
    Jul 2019
    Posts
    1

    Newbee Java and Mongo Questions.

    Sorry I could not find a newbee group to post in. I have little to no experience with Java. You can call me a "learn as I go" dabbler.
    I find it makes much more sense to me if I just try to figure out what it is I need to do rather than learning how to program the space shuttle!

    I am "dabbling" with an evaluation copy of a Apache-Tomcat based application. Out of the box it works as advertised. Now I want to
    add a little modification that saves a Javascript variable out to a database. In this case Mongo. I have the javascript code and the variable.

    I got a basic connection java file to work (see below). Now I need to get it to accept the javascript variable and store it out to Mongo.

    I will make this short.

    I am using command line for everything I do, so no IDE.

    So I have a java file that I compile like this with no errors:

    Code:
    javac -cp .:bson-3.9.1.jar:mongo-java-driver-3.9.1.jar:mongodb-driver-core-3.9.1.jar:mongodb-driver-3.9.1.jar ConnectToDB.java
    And I run it like this with no errors:

    Code:
    java  -cp .:bson-3.9.1.jar:mongo-java-driver-3.9.1.jar:mongodb-driver-core-3.9.1.jar:mongodb-driver-3.9.1.jar ConnectToDB
    Here is the out put:

    Code:
    Jul 02, 2019 11:29:53 AM com.mongodb.diagnostics.logging.JULLogger log 
    
    INFO: Cluster created with settings {hosts=[localhost:27017], mode=SINGLE, requiredClusterType=UNKNOWN, serverSelectionTimeout='30000 ms', maxWaitQueueSize=500}
    
    Connected to the database successfully 
    
    Credentials ::MongoCredential{
    mechanism=null,
    userName='root',
    source='WebRTCdb',
    password=<hidden>,
    mechanismProperties={}}
    Up to this point the java works fine with mongo.

    So, first question: Is there a better (shorter) way to execute the runtime rather than including all of the .jar files?

    Second question: How can I configure the ConnectToDB.java file so I can pass the javascript variable to it and then save it out to the database?
    A subsequent client will have to do the opposite and read it out of the Mongo db and save it to a javascript variable.
    I've been thinking servlet, but the more I research that method, the more confused I get!

    Thanks in advance for your help!

    Ray

  2. #2
    Join Date
    Jun 1999
    Location
    Eastern Florida
    Posts
    3,856

    Re: Newbee Java and Mongo Questions.

    rather than including all of the .jar files?
    You can leave off any jar files that do not have class definitions used by your program or by any of the classes in the other jar files.
    Normally I create a script that has the full command line so I only need to type the name of the script or click on it.

    There is a class ( netscape.javascript.JSObject) that allowed a java applet program to communicate with javascript. I used it a long time ago when applets were still being used.
    Last edited by Norm; July 3rd, 2019 at 08:12 AM.
    Norm

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)