Found 4336 Articles for Java 8

Is it possible to use this keyword in static context in java?

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

953 Views

A static method or, block belongs to the class and these will be loaded into the memory along with the class. You can invoke static methods without creating an object. (using the class name as reference).Whereas "this" in Java acts as a reference to the current object. But static contexts(methods and blocks) doesn't have any instance they belong to the class.In a simple sense, to use “this” the method should be invoked by an object, which is not always necessary with static methods.Therefore, you cannot use this keyword from a static method.ExampleIn the following Java program, the class ThisExample contains a private ... Read More

Can we return this keyword from a method in java?

Maruthi Krishna
Updated on 29-Jun-2020 12:20:49

5K+ Views

The "this" keyword in Java is used as a reference to the current object, within an instance method or a constructor. Using this you can refer the members of a class such as constructors, variables, and methods.Returning “this”Yes, you can return this in Java i.e. The following statement is valid.return this;When you return "this" from a method the current object will be returned.ExampleIn the following Java example, the class Student has two private variables name and age. From a method setValues() we are reading values from user and assigning them to these (instance) variables and returning the current object.public class Student ... Read More

What are the uses of super keyword in java?

Maruthi Krishna
Updated on 29-Jun-2020 12:23:24

859 Views

The super keyword in Java is a reference to the object of the parent/superclass. Using it, you can refer/call a field, a method or, a constructor of the immediate superclass.Referring to a field using super keywordAs mentioned above, you can refer to an instance filed/variable of the immediate superclass from an instance method or, a constructor of a subclass, using the "super" keyword.If a class extends another class, a copy of members of the parent class will be created in the subclass i.e. Using the object of the subclass you can access the members of both subclass and the superclass.If ... Read More

How to count rows – count (*) and Java

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

8K+ Views

The SQL Count() function returns the number of rows in a table. Using this you can get the number of rows in a table.select count(*) from TABLE_NAME;Let us create a table with name cricketers_data in MySQL database using CREATE statement as shown below −CREATE TABLE cricketers_data(    First_Name VARCHAR(255),    Last_Name VARCHAR(255),    Date_Of_Birth date,    Place_Of_Birth VARCHAR(255),    Country VARCHAR(255), );Now, we will insert 5 records in cricketers_data table using INSERT statements −insert into cricketers_data values('Shikhar', 'Dhawan', DATE('1981-12-05'), 'Delhi', 'India'); insert into cricketers_data values('Jonathan', 'Trott', DATE('1981-04-22'), 'CapeTown', 'SouthAfrica'); insert into cricketers_data values('Kumara', 'Sangakkara', DATE('1977-10-27'), 'Matale', 'Srilanka'); insert into cricketers_data values('Virat', 'Kohli', DATE('1988-11-05'), 'Delhi', ... Read More

Can we return Result sets in JDBC?

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

1K+ Views

Yes, just like any other objects in Java we can pass a ResultSet object as a parameter to a method and, return it from a method.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 values(2, 'Jonathan', 'Trott', DATE('1981-04-22'), 'CapeTown', 'SouthAfrica'); insert into MyPlayers values(3, 'Kumara', 'Sangakkara', ... Read More

How to delete all records from a table in Oracle using JDBC API?

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

2K+ Views

The SQL TRUNCATE statement is used to delete all the records from a table.SyntaxTRUNCATE TABLE table_name;To delete all the records from a table from using JDBC API you need to −Register the Driver: Register the driver class using the registerDriver() method of the DriverManager class. Pass the driver class name to it, as parameter.Establish a connection: Connect to the database using the getConnection() method of the DriverManager class. Passing URL (String), username (String), password (String) as parameters to it.Create Statement: Create a Statement object using the createStatement() method of the Connection interface.Execute the Query: Execute the query using the execute() method of the Statement interface.Following JDBC program ... Read More

How to create a Stored procedure in Oracle database using JDBC API?

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

562 Views

Stored procedures are sub routines, segment of SQL statements which are stored in SQL catalog. All the applications that can access Relational databases (Java, Python, PHP etc.), can access stored procedures.Stored procedures contain IN and OUT parameters or both. They may return result sets in case you use SELECT statements. Stored procedures can return multiple result sets.To create a stored procedure in (MySQL) a database using JDBC API you need to −Register the Driver: Register the driver class using the registerDriver() method of the DriverManager class. Pass the driver class name to it, as parameter.Establish a connection: Connect to the database using the getConnection() method ... Read More

How to remove a record from an existing table in oracle database using JDBC API?

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

443 Views

You can remove a particular record from a table in a database using the DELETE query.SyntaxDELETE FROM table_name WHERE [condition];To delete a record from a table using JDBC API you need to −Register the Driver: Register the driver class using the registerDriver() method of the DriverManager class. Pass the driver class name to it, as parameter.Establish a connection: Connect to the database using the getConnection() method of the DriverManager class. Passing URL (String), username (String), password (String) as parameters to it.Create Statement: Create a Statement object using the createStatement() method of the Connection interface.Execute the Query: Execute the query using the executeUpdate() method of the ... Read More

How to retrieve a record from an existing table in oracle database using JDBC API?

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

1K+ Views

You can update/modify the existing contents of a record in a table using the UPDATE query. Using this you can update all the records of the table or specific records.SyntaxUPDATE table_name SET column1 = value1, column2 = value2...., columnN = valueN WHERE [condition];To update the contents of a record in a table using JDBC API you need to −Register the Driver: Register the driver class using the registerDriver() method of the DriverManager class. Pass the driver class name to it, as parameter.Establish a connection: Connect to the database using the getConnection() method of the DriverManager class. Passing URL (String), username (String), password (String) ... Read More

How to drop a table from Oracle database using JDBC API?

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

191 Views

You can insert records into a table using the INSERT query.SyntaxINSERT INTO TABLE_NAME (column1, column2, column3, ...columnN) VALUES (value1, value2, value3, ...valueN); Or, INSERT INTO TABLE_NAME VALUES (value1, value2, value3, ...valueN);To insert a record into a table in a database using JDBC API you need to −Register the Driver: Register the driver class using the registerDriver() method of the DriverManager class. Pass the driver class name to it, as parameter.Establish a connection: Connect to the database using the getConnection() method of the DriverManager class. Passing URL (String), username (String), password (String) as parameters to it.Create Statement: Create a Statement object using the createStatement() ... Read More

Advertisements