Java MongoDB : Insert a document

In this tutorial we will see how to insert a document in mongodb using java driver. To create the document using the Java driver, we use the Document class.   In this example we will also create an embedded document. Tools used mongo java driver : 3.3.0 mongodb : 3.2.8 maven : 3 java : … [Read more…]

Java MongoDB – Auto Sequence ID example

In this tutorial, we will show you how to generate an auto-incrementing sequence id in MongoDB using Java. Here is the clean example and we will implement it in java. Tools Used Mongodb version :  3.2.8 Mongo Java driver : 3.3.0 Java version: 1.7 Eclipse : 4.5 Maven dependency Java Example  

org.postgresql.util.PSQLException: ERROR: invalid input syntax for integer: “”

Recently I was working on a project where I faced an issue. A column in a GUI was sorting properly for sometime but stopped working suddenly one day. Let us start debugging the issue. Exception org.postgresql.util.PSQLException: ERROR: invalid input syntax for integer: “” Problem Code So we starting looking at the code and found a query … [Read more…]

Largest of three numbers java program


Overview Here is a java program to find the largest of the three numbers.  In this example the user will input three numbers and the program will output the largest number Largest of three numbers Example output:

Generate Unique id using UUID in java

Java provides a class java.util.UUID which can be used to generate a randon UUID. Here is a sample code to create a UUID. Output: So the above code can be used to assign ids to entities e.g; Suppose you are writing Person java class and want each person to have a unique id, you can use … [Read more…]

Convert an int to a String in java

How to convert an int to a String in java? Integer to String conversion can be done using a number of options. Let us look at some of them. String.valueOf(int) String class provides utility methods to convert an int to a String. String.valueOf(int) method is very widely used and is considered a good practice for conversion. … [Read more…]

Download an Excel using Servlet

How to download an Excel using Servlet? Create a workbook using any frameworks and write out the created workbook to response.getoutputstream(). For creating the excelsheet I am using apache poi. Set the content type of response to “application/” and set response header as   “Content-Disposition”, “attachment; filename=YourExcelName.xls”. Download an Excel using Servlet Example   Discussion Should I close HttpServletResponse.getOutputStream()? You … [Read more…]