Extract data from a MongoDB database using the Mongo Java Driver - java

I'm trying to write a program in Java that will connect to a MongoDB database. I already have the server, port, name, userDB, and username/password of the MongoDB database I'm trying to access.
I wasn't really sure where to start, so after looking around for a bit, I found a Java driver for MongoDB available on GitHub:
https://github.com/mongodb/mongo-java-driver. I downloaded the source code and imported it as a project on Eclipse. The source code for the driver has literally hundreds if not thousands of files. I tried running it as is, and couldn't get the project to compile.
I have no clue where to go from here. There isn't a lot of in-depth instructional material out there for this, and if I took the time to thoroughly inspect all the files in the driver, that could take decades.

You are on the right track here. What you need to do instead of downloading the source code is to download the JAR files or alternatively use Maven which is a dependency management tool.
This is what you will need to install the mongodb driver.
After you have successfully added the dependencies to your project. Use this quick start guide which will step you through the basics.
Here is an example of working with maven.
Don't get disheartened by small trials..there's always decades of documentation to read ;)

Download the .JAR file from here: https://oss.sonatype.org/content/repositories/releases/org/mongodb/mongodb-driver/3.0.0/
You need mongodb-driver-3.0.0.jar from this list.
Once you have that add it as a library dependency in your Eclipse project and you'll be all set.

Related

JDBC and MS SQL Server Driver for Java 9

So, I am trying to set everything up to use MS SQL Server 2017 from IntelliJ IDEA, and so far I've been able to connect the IDE to the Databases (Gotta love DataGrip), I'm able to see the tables and everything:
However, Microsoft hasn't developed a suitable Driver that supports Java 9, other than this.
The thing is, I have no idea how to even try to test what they are working on in that GitHub link; I tried to replicate what you would do to install a Driver for older Java versions (For example, Driver 6.2), but to no avail.
It isn't the Data source config, since if it was that, I wouldn't even be able to see the Employee DB, nor all it's contents. Also, the 'Pepe' table name it's just for testing purposes.
What I'm asking for, is someone who can tell me where or what to do with the .jar files that contain said still-in-development driver, so I can make queries with the JDBC.
The file that Microsoft offered to download and test contains this structure:
target.zip
|
|
|--mssql-jdbc-6.3.6-SNAPSHOT.jre8-preview.jar (For Java 8, I guess)
|--mssql-jdbc-6.3.6-SNAPSHOT.jre9-preview.jar (For Java 9, I guess)
Thanks for any help.
Well, it appears that it was as easy as moving the .jar file to the libraries used by the project.
Since I'm using IntelliJ, all I had to do is follow this perfect guide, select the .jar from Microsoft and works perfectly!
To anyone with similar problems, just download the necessary Driver, move the .jar to the libraries used by your project however you do it with a different IDE, and you're ready.

Import Neo4J API in Netbeans

For a project I am building a Java GUI from which queries can be sent to Neo4j, to make it easier to do particular analyses. To get this all working, I have downloaded a .jar folder containing all relevant classes (neo4j-javadocs-2.1.7-javadoc.jar). I have loaded the library through the project->properties->libraries->Add JAR, but I can't seem to import the classes I want to use in my GUI (neither automatically nor manually).
I am dabbling in Java, so it is probably a basic oversight that I am making, but with the help from tutorials online and trying different commands (like entering the path of the .jar file) I can't get it working. One of these tutorials is specific on the Neo4j library, so I am very confused. That tutorial is written for Eclipse, instead of NetBeans which I am working with, but as far as my knowledge goes that shouldn't matter for the commands
I don't have enough reputation to post direct images, but this link contains a screenshot. If more information is required, let me know. http://i.stack.imgur.com/lUytK.png
Additionally, when I normally add a class that is not imported, there is an automatic function to import the class. This option is missing for my specific class, so maybe I added the library in an incorrect way?
http://i.stack.imgur.com/QeDX4.png
Edit: Issue resolved thanks to a colleague that came in. Apparently I loaded the Javadoc where I should have loaded to individual classes from the lib directory.
It really should work.
Try to save all changes. NetBeans reparses the classes when you save them.
Try to build your project manually from command line using Ant build script
Use Maven, Ivy or Gradle for Dependency Management then you can depend on the Neo4j artifacts.
For sending queries to the server you actually don't need Neo4j artifacts.
You can also use the JDBC driver, see http://neo4j.com/developer/java

Why I cannot find database explorer in my eclipse ide?

I am following a tutorial to teach myself about some mysql techniques, but at the step to use eclipse to connect mysql database, this tutorial says that there should be a database explorer nearby the console window, but I did not find it and I've searched a lot, I did not find it at window->show view either.
My question is how can I get this database explorer in Eclipse.
Thank you, all commentors and visitors, I found data source explorier http://marketplace.eclipse.org/taxonomy/term/3,31
And install oracle Database Tools for Luna, but it seems that this only supports oracle database, so, let me change my question, how can I build database GUI connection to mySQL workbench in eclipse?
Thank you, all commentors and visitors, especially #PM 77-1, I solved the problem with your help,
generally speaking, I need three things to initialize my JDBC tutorial,
1.MySQL
2.Eclipse and a nice plugin as an option
3.JDBC driver, for me it is mysql driver mysql.com/products/connector
use the #PM 77-1 provided tutorial to set up the project to manipulate the database.
But if you need a database GUI in Eclipse like me, you will need a plugin like DBview, my initial one database explorer is no longer in Eclipse. And remember to download the JDBC driver with .jar as the end. It can be find at platform independent version.
Ok that's all.

How to convert a jar file to an executable with MySQL in it?

I have a java application which uses MySQL as its database. In order to deliver the project, I need to convert it to an executable with MySQL included. I have tried exe4j but it doesn't allow to include the database. Please advice. The project is done in Netbeans.
Although it's not being actively developed any longer due to low demand, you can have a look at the MySQL-Connector/MXJ package that's meant for "embedding" your MySQL-database into your application - I recon' it still should be able to do the trick.
But to be honest, the most future-proof solution would be to switch out your database with another option, preferably an in memory database such as H2database or SQLite.

Finished Java project, now creating jar or .exe file (with Database)

So, i've just finished a small java application, with database and stuff...
I used Netbeans and Mysql, now i want to export my project so i can use it anywhere i want;
any computer, even with no Mysql or Java installed!
So, i've tried some programs like Launch4j or something... but the main problem is, even if i make the .exe file, what's gonna happen with the database? it's located in my PC, so if somebody try to use my application, he can't access to the database, so the application won't work...
In other words...What is the solution that i can use to like "Combine" the database with the application, if it is possible? or create the .exe file with the database...
I hope that my problem is clear, and thank you for your answers :)
You can look at MySQL Connector/MXJ to embed your mysql database in your application.
But be aware that this package is no longer under active development:
Due to very low demand, MySQL
has stopped development and support for Connector/MXJ. Source and
binaries for previously released versions will continue to be
available from archives.
An alternative solutation would be using another database like SQLite, H2 or HSQLDB
You can create an executable jar by exporting your project through eclipse. You can do this by following these steps:
Right click on the Project
Export as Jar file
When you were programming in netbeans did you include the database within netbeans? Here is a guide on how to do this.
https://netbeans.org/kb/docs/ide/mysql.html
Also here is a second guide on how to Packaging and Distributing Java Desktop Applications
https://netbeans.org/kb/docs/java/javase-deploy.html
I hope these help.
If not just go over your step you took to build the app.
if you really want to give your users a good experience, I would suggest you implement a embedded database in your application instead.
Look at: http://www.h2database.com/
It's free and open source and I use it heavily myself.
It supports embedded (where it creates flat database files on the computer), in-memory, and server-mode, where you have the possibility of letting multiple-applications share the same database.
It's just a jar file you include in your application, and then the users wont have to install neither MySQL, have access to MySQL on a network drive or need other database software installed.
(depending on your requirements, it might also be a good idea to look into Hibernate, to have some more abstraction between the different RDBMS).
In order to get a database built-in to the application, consider HSQLDB, which is an in-memory database.
http://hsqldb.org/
It can run entirely in the JVM without any external resources.

Categories