Articles on Trending Technologies

Technical articles with clear explanations and examples

How to prevent resizing columns in a JTable

Anvi Jain
Anvi Jain
Updated on 30-Jul-2019 1K+ Views

To prevent resizing columns, use the method setResizingAllowed(). Here, we will set setResizingAllowed() to false for table header to disallow resizing of columns from header −table.getTableHeader().setResizingAllowed(false);Let us first see an example wherein we can easily resize columns in a table by resizing the table column header −Examplepackage my; import java.awt.Color; import java.awt.Font; import javax.swing.JFrame; import javax.swing.JScrollPane; import javax.swing.JTable; import javax.swing.table.DefaultTableModel; public class SwingDemo {    public static void main(String[] argv) throws Exception {       DefaultTableModel tableModel = new DefaultTableModel();       JTable table = new JTable(tableModel);       tableModel.addColumn("Language/ Technology");       tableModel.addColumn("Text Tutorial");   ...

Read More

What is consensus protocol in Block Chain?

Prasanna Kotamraju
Prasanna Kotamraju
Updated on 30-Jul-2019 742 Views

Consensus protocol is one of the most important aspects that makes the Block chain network a fool proof system. It is the revolutionary protocol that makes the Block chain network an irrefutable system where the majority of devices (nodes) connected to the network agree on each and every transaction. This prevents exploitation of the system as more than 51% consensus is required to create a new block. It is the core of the Block Chain which makes it certain that the information stored on the Block Chain is accurate and honest.The very core of the Nakamoto’s Block chain consensus protocol ...

Read More

How to insert/store JSON array into a database using JDBC?

Nishtha Thakur
Nishtha Thakur
Updated on 30-Jul-2019 10K+ Views

A Json array is an ordered collection of values that are enclosed in square brackets i.e. it begins with ‘[’ and ends with ‘]’. The values in the arrays are separated by ‘, ’ (comma).Sample JSON array{    "books": [ Java, JavaFX, Hbase, Cassandra, WebGL, JOGL] }The json-simple is a light weight library which is used to process JSON objects. Using this you can read or, write the contents of a JSON document using Java program.JSON-Simple maven dependencyFollowing is the maven dependency for the JSON-simple library −           com.googlecode.json-simple       json-simple       ...

Read More

Middle of three using minimum comparisons in C++

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

In this section, we will see how to find the middle of three given values by comparing them. So if three numbers are given like (10, 30, 20), then it will find 20 as this is the middle element. Let us see the algorithm first, then we will implement that algorithm into C++ code.Algorithmmiddle_of_three(a, b, c): Input: Three numbers a, b and c Output: The middle of these three Begin    if a > b, then       if b > c, then          return b       else if a > c, then   ...

Read More

How to get the list of all databases using JDBC?

Vikyath Ram
Vikyath Ram
Updated on 30-Jul-2019 3K+ Views

You can get the list of databases in MySQL using the SHOW DATABASES query.show databases;Following JDBC program retrieves the list of databases by executing the show databases query.Exampleimport java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.Statement; public class ShowDatabasesExample {    public static void main(String args[]) throws Exception {       //Registering the Driver       DriverManager.registerDriver(new com.mysql.jdbc.Driver());       //Getting the connection       String mysqlUrl = "jdbc:mysql://localhost/mydatabase";       Connection con = DriverManager.getConnection(mysqlUrl, "root", "password");       System.out.println("Connection established......");       //Creating a Statement object       Statement stmt = con.createStatement(); ...

Read More

What is the difference between a destructor and a free function in C++?

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

Here we will see what are the differences between destructor and the free() functions in C++. The destructor is used to perform some action, just before the object is destroyed. This action may not freeing up the memory, but can do some simple action such as displaying one message on screen.The free() function is used in C, in C++, we can do the same thing using delete keyword also. When the object is deleted using free() or delete, the destructor is invoked. The destructor function takes no argument and returns nothing. This function is called when free or delete is ...

Read More

How to get all the column names from a ResultSet using JDBC

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

You can get the name of a particular column using the getColumnName() method of the ResultSetMetadata interface.This method accepts an integer value representing the index of a column and returns a String value representing the name of the specified column.Let us create a table with name MyPlayers in MySQL database using CREATE statement as shown below −CREATE TABLE MyPlayers(    ID INT,    First_Name VARCHAR(255),    Last_Name VARCHAR(255),    Date_Of_Birth date,    Place_Of_Birth VARCHAR(255),    Country VARCHAR(255),    PRIMARY KEY (ID) );Now, we will insert 7 records in MyPlayers table using INSERT statements −insert into MyPlayers values(1, 'Shikhar', 'Dhawan', DATE('1981-12-05'), 'Delhi', 'India'); insert into MyPlayers ...

Read More

Set whether the row in the table model can be selected or deselected in Java?

George John
George John
Updated on 30-Jul-2019 525 Views

We can set or disallow selection of row in the table using setRowSelectionAllowed().Let’s say the following is our table −DefaultTableModel tableModel = new DefaultTableModel(); JTable table = new JTable(tableModel);If you want to allow selection of row, then set the method to TRUE −table.setRowSelectionAllowed(true);If you want to disallow selection of row, then set the method to FALSE −table.setRowSelectionAllowed(false);We have disallowed selection of rows in the below example −Examplepackage my; import javax.swing.JFrame; import javax.swing.JScrollPane; import javax.swing.JTable; import javax.swing.table.DefaultTableModel; public class SwingDemo {    public static void main(String[] argv) throws Exception {       DefaultTableModel tableModel = new DefaultTableModel();       ...

Read More

Java ResultSetMetaData getColumnName() method with example

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

The getColumnName() method of the ResultSetMetaData (interface) retrieves and returns the name of the specified column in the current ResultSet object.This method accepts an integer value representing the index of a column and, returns a String value representing the name of the specified column.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 ...

Read More

How to set JAVA_HOME environment variables on Windows OS in Java?

raja
raja
Updated on 30-Jul-2019 2K+ Views

Once you have installed JDK version on your windows machine, you have to set up Environment Variables.Please find below steps to set the java pathGo to My Computer ---> Right Click on it ---> Advanced System Settings ---> Advanced Tab ---> Click on Environment VariablesNow you have to alter the “Path” variable under system variables such that it contains a path to Java Environment. Select the path variable and click on the “Edit” buttonBy default, Java is installed in “C:\Program Files\Java\jre version\bin” in case you have changed the location of installation, then add that pathClick on OK button and now ...

Read More
Showing 58221–58230 of 61,297 articles
Advertisements