Programming Articles

Page 2445 of 2547

Java ResultSet wasNull() method with example

Arushi
Arushi
Updated on 30-Jul-2019 9K+ Views

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 wasNull() method of the ResultSet interface determines whether the last column read had a Null value. i.e. whenever you read the contents of a column of the ResultSet using the ...

Read More

How to set columnWeights and rowWeights in a GridBagLayout?

Smita Kapse
Smita Kapse
Updated on 30-Jul-2019 295 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 double[]{0.0f, 0.0f, 2.0f}; layout.rowWeights = new double[]{0.0f, 1.0f};Now, set the constraints for the label and add it to the panel −gbc.gridx = 0; gbc.gridy = 0; layout.setConstraints(label, gbc); panel.add(label);The following is an example to set columnWeights and rowWeights in a GridBagLayout −Examplepackage my; import java.awt.GridBagConstraints; import java.awt.GridBagLayout; import javax.swing.JFrame; import ...

Read More

C++ Program to Solve a Matching Problem for a Given Specific Case

Smita Kapse
Smita Kapse
Updated on 30-Jul-2019 535 Views

This is a C++ Program to solve a matching problem for a Given Specific Case. Here, N men and N women are given, each person has ranked all members of the opposite gender in order of preference, marry the men and women together such that there are no two people of opposite gender who would both rather have each other than their current partners. All the marriages are “stable”, if there are no such people exists.AlgorithmsBegin    function WomenPrefersMenOverMen1():    A) Check if women prefer men over her current engagement men1    B) If men1 comes before men in list ...

Read More

Java ResultSetMetaData getColumnCount() method with example?

Rishi Raj
Rishi Raj
Updated on 30-Jul-2019 2K+ Views

The getColumnCount() method of the ResultSetMetaData (interface) retrieves the number of the columns of the current ResultSet object.This method returns an integer value representing the number of columns.To get the ResultSetMetaData object, you need to:Register the Driver: Select the required database register the Driver class of the particular database using the registerDriver() method of the DriverManager class or, the forName() method of the class named Class.DriverManager.registerDriver(new com.mysql.jdbc.Driver());Get connection: Create a connection object by passing the URL of the database, username and password of a user in the database (in string format) as parameters to the getConnection() method of the DriverManager class.Connection mysqlCon = ...

Read More

Distribute extra horizontal and vertical space in a GridBagLayout with Java

Nishtha Thakur
Nishtha Thakur
Updated on 30-Jul-2019 939 Views

To distribute the extra horizontal and vertical space, use the fields weightx and weighty. The following is an example to distribute extra horizontal and vertical space −Examplepackage my; import java.awt.GridBagConstraints; import java.awt.GridBagLayout; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JTextArea; import javax.swing.WindowConstants; public class SwingDemo {    public static void main(String[] args) {       JFrame frame = new JFrame("Demo Frame");       JPanel panel = new JPanel();       GridBagLayout layout = new GridBagLayout();       panel.setLayout(layout);       GridBagConstraints gbc = new GridBagConstraints();       JLabel label = new JLabel("Rank: ");   ...

Read More

C++ Program to Generate All Pairs of Subsets Whose Union Make the Set

Samual Sam
Samual Sam
Updated on 30-Jul-2019 337 Views

This is a C++ program to generate all pairs of subsets, whose union make the Set.AlgorithmsBegin    function UnionSet():    Arguments:       a[] = an array.       n = number of elements.       Body of the function:       1) Generate binary code from 0 to 2^(n-1)-1 for all 2^(n-1) pairs.       2) Print the array element which has 0 or 1 in corresponding indexes in code string for each code.       3) Print them in a different set, which on the union of both sets gives the super set. EndExample#include #include #include using namespace std; void display(char code[], int a[], int n) //display the pairs {    int i;    cout

Read More

How to disallow resizing component with GridBagLayout in Java

Anvi Jain
Anvi Jain
Updated on 30-Jul-2019 915 Views

To disallow resizing component with GridBagLayout, use the GridBagConstraints NONE constant −GridBagConstraints gbc = new GridBagConstraints(); gbc.fill = GridBagConstraints.NONE;The following is an example to disallow resizing component with GridBagLayout −Examplepackage my; import java.awt.GridBagConstraints; import java.awt.GridBagLayout; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JTextArea; import javax.swing.WindowConstants; public class SwingDemo {    public static void main(String[] args) {       JFrame frame = new JFrame("Demo Frame");       JPanel panel = new JPanel();       GridBagLayout layout = new GridBagLayout();       panel.setLayout(layout);       GridBagConstraints gbc = new GridBagConstraints();       gbc.fill = GridBagConstraints.NONE;   ...

Read More

C++ Program to Find Whether a Path Exists Between 2 Given Nodes

Nishtha Thakur
Nishtha Thakur
Updated on 30-Jul-2019 369 Views

This is a C++ program to find whether a path exists between 2 given nodesAlgorithmBegin    function isReach() is a recursive function to check whether d is reachable to s:    A) Mark all the vertices as unvisited.    B) Mark the current node as visited and enqueue it and it will be used to get all adjacent vertices of a vertex.    C) Dequeue a vertex from queue and print it.    D) Get all adjacent vertices of the dequeued vertex s.    E) If an adjacent has not been visited, then mark it visited and enqueue it.   ...

Read More

Java ResultSetMetaData getCatalogName() method with example

Rishi Raj
Rishi Raj
Updated on 30-Jul-2019 332 Views

In general a catalog is a directory which holds information about data sets, file or, a database. Whereas, in a database, catalog holds the list of all the databases, base tables, views (virtual tables), synonyms, value ranges, indexes, users, and user groups.The getCatalogName() method of the ResultSetMetaData (interface) retrieves the name of the catalog of the table containing a particular column.This method accepts an integer value representing the index of the column in the current ResultSet object, as an argument and, returns a String value representing the name of the catalog.To get the ResultSetMetaData object, you need to −Register the Driver: Select the ...

Read More

Set a component and place it next to the previously added component with GridBagLayout in Java

Nishtha Thakur
Nishtha Thakur
Updated on 30-Jul-2019 219 Views

We have set a component first −GridBagConstraints constraints = new GridBagConstraints(); constraints.gridy = 0; panel.add(new JButton("First row"), constraints);Now, we will place it next to the previously added component −constraints.gridx = GridBagConstraints.RELATIVE; constraints.gridy = 1; panel.add(new JButton("2nd row 1st column"), constraints); panel.add(new JButton("2nd row 2nd column"), constraints);Examplepackage my; import java.awt.GridBagConstraints; import java.awt.GridBagLayout; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JPanel; public class SwingDemo {    public static void main(String[] args) {       JFrame frame = new JFrame();       frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);       JPanel panel = new JPanel();       panel.setLayout(new GridBagLayout());       GridBagConstraints constraints = new ...

Read More
Showing 24441–24450 of 25,466 articles
Advertisements