Smita Kapse has Published 498 Articles

How can fetch records from specific month and year in a MySQL table?

Smita Kapse

Smita Kapse

Updated on 30-Jul-2019 22:30:26

683 Views

Use YEAR() and MONTH() to display records from specific month and year respectively. Let us first create a table −mysql> create table DemoTable    (    CustomerId int NOT NULL AUTO_INCREMENT PRIMARY KEY,    CustomerName varchar(20),    CustomerTotalBill int,    PurchasingDate date    ); Query OK, 0 rows affected (0.83 ... Read More

C++ Program to Create a Random Linear Extension for a DAG

Smita Kapse

Smita Kapse

Updated on 30-Jul-2019 22:30:26

154 Views

Here we will see how to create Random Linear Extension of a Directed Acyclic Graph (DAG). The Linear extension is basically the topological sorting of DAG. Let us consider the graph is like below −The topological sorting for a directed acyclic graph is the linear ordering of vertices. For every ... Read More

How to combine FlowLayout and BoxLayout in Java?

Smita Kapse

Smita Kapse

Updated on 30-Jul-2019 22:30:26

620 Views

To combine both the layouts, here we have created two panels −Frame f = new JFrame("Combining Layouts"); JPanel panel1 = new JPanel(); JPanel panel2 = new JPanel();Now, set the layouts accordingly −panel1.setLayout(new BoxLayout(panel1, BoxLayout.Y_AXIS)); panel2.setLayout(new FlowLayout());Then after adding components to both the panels, add them to the frame −f.add(panel1, BorderLayout.WEST); ... Read More

Use result from MongoDB in shell script?

Smita Kapse

Smita Kapse

Updated on 30-Jul-2019 22:30:26

544 Views

Let us first create a collection with a document −>db.useResultDemo.insertOne({"StudentFirstName":"Robert"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cda70f5b50a6c6dd317adcd") }Display all documents from a collection with the help of find() method −> db.useResultDemo.find();Following is the output −{ "_id" : ObjectId("5cda70f5b50a6c6dd317adcd"), "StudentFirstName" : "Robert" }Here is the query to use result ... Read More

How to set columnWeights and rowWeights in a GridBagLayout?

Smita Kapse

Smita Kapse

Updated on 30-Jul-2019 22:30:26

211 Views

Create a panel and set the layout −JPanel panel = new JPanel(); GridBagLayout layout = new GridBagLayout(); panel.setLayout(layout);Now, set the constrainst and with that the columnWeights and rowWeights −GridBagConstraints gbc = new GridBagConstraints(); JLabel label = new JLabel("Rank: "); JTextArea text = new JTextArea(); text.setText("Add rank here..."); layout.columnWeights = new ... Read More

Write a one line C function to round floating point numbers

Smita Kapse

Smita Kapse

Updated on 30-Jul-2019 22:30:26

759 Views

Here we will see how to write one-line C function, that can round floating point numbers. To solve this problem, we have to follow these steps.Take the numberif the number is positive, then add 0.5Otherwise, subtract 0.5Convert the floating point value to an integer using typecastingExample#include    int my_round(float ... Read More

How to create a user in MongoDB v3?

Smita Kapse

Smita Kapse

Updated on 30-Jul-2019 22:30:26

194 Views

To create a user in MongoDB v3, use the createUser() method. This allows you to create a user and while creating you need to add user, password, and roles as well. These roles assign permissions. The syntax is as follows −use admin db.createUser(    {       user: “yourUserName", ... Read More

How to add components with a Relative X Position in Java

Smita Kapse

Smita Kapse

Updated on 30-Jul-2019 22:30:26

623 Views

To add components with a relative X position, use the GridBagConstraints.RELATIVE constant. Set this to gridx field −GridBagConstraints constraints = new GridBagConstraints(); constraints.gridx = GridBagConstraints.RELATIVE;The following is an example to add components with a relative X position in Java −Examplepackage my; import java.awt.GridBagConstraints; import java.awt.GridBagLayout; import javax.swing.JButton; import javax.swing.JFrame; import ... Read More

Retrieve the position in an Array in MongoDB?

Smita Kapse

Smita Kapse

Updated on 30-Jul-2019 22:30:26

323 Views

You can use the concept of map reduce to get the position in an array. Let us first create a collection with documents −> db.retrievePositionDemo.find(); { "_id" : ObjectId("5cd569ec7924bb85b3f4893f"), "Subjects" : [ "MySQL", "MongoDB", "Java" ] }Following is the query to display all documents from a collection with the help ... Read More

How to set vertical alignment for a component in Java?

Smita Kapse

Smita Kapse

Updated on 30-Jul-2019 22:30:26

4K+ Views

For vertical alignment, create a frame and set the layout using the BoxLayout manager −JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.getContentPane().setLayout(new BoxLayout(frame.getContentPane(), BoxLayout.Y_AXIS));Above, we have set the BoxLayout to set the alignment since it is a layout manager that allows multiple components to be laid out either vertically or horizontally. ... Read More

Advertisements