To get a list of all databases, you need to use the below syntax −use admin db.runCommand({listDatabases: 1});To get a list of all collection names of a particular database, you need to use below syntax −use yourDatabaseName; db.getCollectionNames();Let us implement the above syntaxes −Case 1 − To get a list of databases> use admin switched to db admin > db.runCommand({listDatabases: 1});This will produce the following output −{ "databases" : [ { "name" : "admin", "sizeOnDisk" : 1675264, "empty" : false ... Read More
To create right justified JTextField, set the alignment to be RIGHT. Here, we will be using the setHorizontalAlignment() method as well and within that the alignment would be set.Create a JTextField −JTextField emailId = new JTextField(20);Now, align it to the right −emailId.setHorizontalAlignment(JTextField.RIGHT);The following is an example to create right justified JTextField −Examplepackage my; import java.awt.FlowLayout; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JTextField; import javax.swing.SwingConstants; public class SwingDemo { public static void main(String[] args) throws Exception { JFrame frame = new JFrame("Enter emailid..."); JLabel label; frame.setLayout(new FlowLayout()); label = ... Read More
Use the $pull to remove array elements from a MongoDB document as shown in the following syntax −db.yourCollectionName.update( { }, { $pull: { yourFieldName: yourValue }}, {multi:true });Let us first create a collection with documents −>db.removeArrayElementsDemo.insertOne({"AllPlayerName":["John", "Sam", "Carol", "David"]}); { "acknowledged" : true, "insertedId" : ObjectId("5cd90d011a844af18acdffc1") } >db.removeArrayElementsDemo.insertOne({"AllPlayerName":["Chris", "Robert", "John", "Mike"]}); { "acknowledged" : true, "insertedId" : ObjectId("5cd90d2e1a844af18acdffc2") }Following is the query to display all documents from a collection with the help of find() method −> db.removeArrayElementsDemo.find().pretty();This will produce the following output −{ "_id" : ObjectId("5cd90d011a844af18acdffc1"), "AllPlayerName" : [ "John", ... Read More
The HTML DOM Input Color Object represents an input HTML element with type color.SyntaxFollowing is the syntax −Creating an with type color −var colorObject = document.createElement(“input”); colorObject.type = “color”;AttributesHere, “colorObject” can have the following attributes −AttributesDescriptionautocompleteIt defines the value of autocomplete attribute of a color pickerautofocusIt defines if the color picker should be focused on initial page load.defaultValueIt sets/returns the default value of color pickerdisabledIt defines if color picker is disabled/enabledformIt returns a reference of enclosing form that contains the color pickernameIt defines the value of name attribute of a color pickertypeIt returns the type of form element of ... Read More
The HTML DOM Input Time form property returns the reference of enclosing form for input Time.SyntaxFollowing is the syntax −Returning reference to the form objectinputTimeObject.formExampleLet us see an example of Input Time form property − Live Demo Input Time form form { width:70%; margin: 0 auto; text-align: center; } * { padding: 2px; margin:5px; } input[type="button"] { border-radius: 10px; } Time-form Examination Time : var divDisplay = document.getElementById("divDisplay"); var inputTime = document.getElementById("TimeSelect"); function getform() { divDisplay.textContent = inputTime.form.id+' exam starts from '+inputTime.value; } OutputThis will produce the following output −Before clicking ‘Which Exam?’ button −After checking ‘Which Exam?’ button −
Here we will see the effect of nextafter() and nextforward() functions in C or C++. These functions are present in the math.h or cmath library.if the functions are like nextafter(a, b) and nextforward(a, b). These functions are used to find the next representable value after a in the direction of b. The nextforward() has more precise second parameter b.Example#include #include main () { //The nextafter function() printf ("Smallest representable number after 0 towards 1 : %e", nextafter(0.0, 1.0)); printf ("Largest representable number before -1 towards 0 :%e", nextafter(0.0, -1.0)); printf ("Largest +ve representable number ... Read More
When we execute certain SQL queries (SELECT query in general) they return tabular data.The java.sql.ResultSet interface represents such tabular data returned by the SQL statements.i.e. the ResultSet object holds the tabular data returned by the methods that execute the statements which quires the database (executeQuery() method of the Statement interface in general).The ResultSet object has a cursor/pointer which points to the current row. Initially this cursor is positioned before first row.The isClosed() method of the ResultSet interface is used to determine whether the current ResultSet object is closed.rs.isclosed()CLOSE_CURSORS_AT_COMMITIf the holdability of the ResultSet object is set to this value. Whenever you commit/save ... Read More
Use $in operator to get at least one match. Let us first create a collection with documents −> db.atleastOneMatchDemo.insertOne({"StudentFavouriteSubject":["MySQL", "MongoDB"]}); { "acknowledged" : true, "insertedId" : ObjectId("5cd2db5db64f4b851c3a13ce") } > db.atleastOneMatchDemo.insertOne({"StudentFavouriteSubject":["Java", "C", "MongoDB"]}); { "acknowledged" : true, "insertedId" : ObjectId("5cd2db71b64f4b851c3a13cf") } > db.atleastOneMatchDemo.insertOne({"StudentFavouriteSubject":["Python", "C++", "SQL Server"]}); { "acknowledged" : true, "insertedId" : ObjectId("5cd2db87b64f4b851c3a13d0") } >db.atleastOneMatchDemo.insertOne({"StudentFavouriteSubject":["Ruby", "Javascript", "C#", "MySQL"]}); { "acknowledged" : true, "insertedId" : ObjectId("5cd2dba9b64f4b851c3a13d1") }Following is the query to display all documents from a collection with the help of find() method −> db.atleastOneMatchDemo.find().pretty();This will produce the following output −{ "_id" : ... Read More
Yes, we can save the content to a file with FileWriter class. Set a JTextFile component as shown below −JTextField emailId = new JTextField(20); emailId.setText("abc@example.com");Set the file location from to where you want to save the content from the JTextField −String file = "E:ew.txt";Now, with FileWriter, save the content −FileWriter fileWriter = new FileWriter(file); emailId.write(fileWriter); fileWriter.close();The following is an example to save content from JTextFile to a file. Here, we are saving the text from JTextField to a file at location: “E:ew.txt” −Examplepackage my; import java.awt.FlowLayout; import java.io.FileWriter; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JTextField; import javax.swing.SwingConstants; public class SwingDemo { ... Read More
To update all elements in an array with a prefix string, use forEach(). Let us first create a collection with documents −> db.replaceAllElementsWithPrefixDemo.insertOne( { "StudentNames" : [ "John", "Carol" ] } ); { "acknowledged" : true, "insertedId" : ObjectId("5cd91908b50a6c6dd317ad8e") } > > > db.replaceAllElementsWithPrefixDemo.insertOne( { "StudentNames" : [ "Sam" ] } ); { "acknowledged" : true, "insertedId" : ObjectId("5cd9191cb50a6c6dd317ad8f") }Following is the query to display all documents from ... Read More