Found 9150 Articles for Object Oriented Programming

Can interfaces have Static methods in Java?

Maruthi Krishna
Updated on 29-Jun-2020 14:09:24

7K+ Views

An interface in Java is similar to class but, it contains only abstract methods and fields which are final and static.A static method is declared using the static keyword and it will be loaded into the memory along with the class. You can access static methods using class name without instantiation.Static methods in an interface since java8Since Java8 you can have static methods in an interface (with body). You need to call them using the name of the interface, just like static methods of a class.ExampleIn the following example, we are defining a static method in an interface and accessing ... Read More

How to handle indexes in JavaDB using JDBC program?

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

1K+ Views

Indexes in a table are pointers to the data, these speed up the data retrieval from a table. If we use indexes, the INSERT and UPDATE statements get executed in a slower phase. Whereas SELECT and WHERE get executed with in lesser time.Creating an indexCTREATE INDEX index_name on table_name (column_name);Displaying the IndexesSHOW INDEXES FROM table_name;Dropping an indexDROP INDEX index_name;Following JDBC program creates a table with name Emp in JavaDB. creates an index on it, displays the list of indexes and, deletes the created index.Exampleimport java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; import java.sql.Statement; public class IndexesExample {    public static void main(String ... Read More

What are defender methods or virtual methods in Java?

Maruthi Krishna
Updated on 29-Jun-2020 14:10:49

698 Views

The default methods in an interface in Java are also known as defender methods or, virtual methods.The defender/virtual methods are those that will have a default implementation in an interface. You can define defender/virtual methods using the default keyword as −default void display() {    System.out.println("This is a default method"); }There is no need to implement these defender/virtual methods in the implementing classes you can call them directly.If you have an interface which is implemented by some classes and if you want to add a new method int it.Then, you need to implement this newly added method in all the ... Read More

How to drop a table from JavaDB using JDBC?

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

168 Views

You can create a table in a database using the CREATE TABLE query.SyntaxCREATE TABLE table_name( column1 datatype, column2 datatype, column3 datatype, ..... columnN datatype, PRIMARY KEY( one or more columns ) );To create 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 ot 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 ... Read More

How to create a table in JavaDB using JDBC?

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

210 Views

You can create a table in JavaDB database using the CREATE TABLE statement.SyntaxCREATE TABLE table_name (    column_name1 column_data_type1 constraint (optional),    column_name2 column_data_type2 constraint (optional),    column_name3 column_data_type3 constraint (optional) );To create a table in JavaDB using JDBC API you need to −Register the driver − The forName() method of the class, Class accepts a String value representing a class name loads it in to the memory, which automatically registers it. Register the driver using this method.Establish a connection − Connect ot the database using the getConnection() method of the DriverManager class. Passing URL (String), username (String), password (String) ... Read More

How to get the list of all drivers registered with the DriverManager using JDBC?

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

1K+ Views

The java.sql.DriverManager class manages JDBC drivers in your application. This class maintains a list of required drivers and load them whenever it is initialized.Therefore, you need to register the driver class before using it. However, you need to do it only once per application.One way to register a driver class object to Driver manager is the registerDriver() method of the DriverManager class. To this method you need to pass the Driver object as a parameter.//Instantiating a driver class Driver driver = new com.mysql.jdbc.Driver(); //Registering the Driver DriverManager.registerDriver(driver);List of all the DriversYou can get the list of all the drivers registered ... Read More

How to de-register a driver from driver manager’s drivers list using JDBC?

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

680 Views

The java.sql.DriverManager class manages JDBC drivers in your application. This class maintains a list of required drivers and load them whenever it is initialized.Therefore, you need to register the driver class before using it. However, you need to do it only once per application.You can register a new Driver class in two ways −Using the registerDriver() method of the DriverManager class. To this method you need to pass the Driver object as a parameter.//Instantiating a driver class Driver driver = new com.mysql.jdbc.Driver(); //Registering the Driver DriverManager.registerDriver(driver);Using the forName() method of the class named Class. To this method you need to ... Read More

How to write data into BLOB and CLOB type columns in a table using JDBC?

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

3K+ Views

CLOB stands for Character Large Object. in general, an SQL Clob is a built-in datatype which is used to store large amount of textual data. Using this datatype, you can store data up to 2, 147, 483, 647 characters. MYSQL database provides support Clob datatype TINYTEXT, TEXT, MEDIUMTEXT, LONGTEXT.The java.sql.Clob interface of the JDBC API represents the CLOB datatype. Since the Clob object in JDBC is implemented using an SQL locator, it holds a logical pointer to the SQL CLOB (not the data).Inserting Data into a column of Clob typeYou can insert a CLOB type value using the setCharacterStream() or, ... Read More

How to Read data from BLOB and CLOB type columns from a table using JDBC?

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

6K+ Views

Clob datatypeCLOB stands for Character Large Object. in general, an SQL Clob is a built-in datatype which is used to store large amount of textual data. Using this datatype, you can store data up to 2, 147, 483, 647 characters. MYSQL database provides support Clob datatype TINYTEXT, TEXT, MEDIUMTEXT, LONGTEXT.The java.sql.Clob interface of the JDBC API represents the CLOB datatype. Since the Clob object in JDBC is implemented using an SQL locator, it holds a logical pointer to the SQL CLOB (not the data).Reading Data from a column of datatype ClobYou can read CLOB value (character stream data) from a ... Read More

How to get the properties of a driver using JDBC?

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

939 Views

You can get the properties of a driver using the getPropertyInfo() method of the Driver interface.DriverPropertyInfo[] info = driver.getPropertyInfo(mysqlUrl, null);This method accepts a two parameters: A String variable representing the URL of the database, an object of the class Properties and, returns an array of the DriverPropertyInfo objects, where each object holds information about the possible properties of the current driver.From a DriverPropertyInfo object you can get the information such as name of the property, value of the property, description, choices and, if it is required or not, using its fields name, value, description, choices, required, respectively.DriverPropertyInfo[] info = driver.getPropertyInfo(mysqlUrl, ... Read More

Advertisements