Programming Articles - Page 2624 of 3363

Java Connection getMetaData() method with example

Arushi
Updated on 02-Aug-2024 18:19:16

2K+ Views

Generally, Data about data is known as metadata. The DatabaseMetaData interface provides methods to get information about the database you have connected with like, database name, database driver version, maximum column length, etc... The getMetaData() method of the Connection interface retrieves and returns the DatabaseMetaData object. This contains information about the database you have connected to. You can get information about the database such as the name of the database, version, driver name, user name, URL, etc… by invoking the methods of the DatabaseMetaData interface using the obtained object. This method returns the DatabaseMetaData object which holds information about the underlying ... Read More

Java Connection getCatalog() method with example

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

1K+ 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 getCatalog() method of the Connection interface returns the name of the current catalog/database, of the current connection object.This method returns a Sting value representing the name of the catalog. It returns null if there is no catalog.To get the catalog name −Register the driver using the registerDriver() method of the DriverManager class as −//Registering the Driver DriverManager.registerDriver(new com.mysql.jdbc.Driver());Get the connection ... Read More

Java Connection setAutoCommit() method with example

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

5K+ Views

If you commit a database, it saves all the changes that have been done till that particular point. By default, some databases commits/saves the changes done automatically.You can turn off/on the auto-commit using the setAutoCommit() method of the Connection interface.ParameterThis method accepts a boolean value as a parameter. If you pass true to this method it turns on the auto-commit feature of the database and, if you pass false to this method it turns off the auto-commit feature of the database.//Turning off the auto-commit Con.setAutoCommit(false); //Turning on the auto-commit Con.setAutoCommit(true);To change the auto-commit value −Register the driver using the registerDriver() ... Read More

Java Connection getAutoCommit() method with example

Rishi Raj
Updated on 18-Oct-2024 11:56:37

943 Views

In this program, we will establish a connection to a MySQL database and check the current auto-commit setting using the getAutoCommit() method from the Connection interface. We will first disable the auto-commit feature using setAutoCommit(false) and then retrieve the current auto-commit status with getAutoCommit() to verify if it has been successfully disabled. Steps to use the getAutoCommit() method Following are the steps to use the getAutoCommit() method − First, we will import the required java.sql.Connection and java.sql.DriverManager packages. We'll establish a connection to a MySQL database using the DriverManager.getConnection() method. ... Read More

Java Connection releaseSavepoint() method with example

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

522 Views

A save point is a logical rollback point within a transaction. When you set a save point, whenever an error occurs past a save point, you can undo the events you have done up to the created save point using the rollback() method.You can set a save point in a database using the setSavepoint() method of the Connection interface.And, you can remove/release a save point using the releaseSavepoint() method.This method accepts a Savepoint object as a parameter and removes the specified Savepoint.To release a save point −Register the driver using the registerDriver() method of the DriverManager class as −//Registering the Driver DriverManager.registerDriver(new com.mysql.jdbc.Driver());Get the ... Read More

Java Connection rollBack() method with example

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

5K+ Views

A rollback operation undoes all the changes done by the current transaction i.e. If you call a rollBack() method of the Connection interface, all the modifications are reverted until the last commit.Con.rollback()You can also rollback the changes in the database up to a particular save point by passing the required Savepoint object as a parameter to this method as −//Setting the save point con.rollback("MysavePoint");To roll back a transactionRegister the driver using the registerDriver() method of the DriverManager class as −//Registering the Driver DriverManager.registerDriver(new com.mysql.jdbc.Driver());Get the connection using the getConnection() method of the DriverManager class as −//Getting the connection String url = ... Read More

Java Connection setSavepoint() method with example

Alshifa Hasnain
Updated on 11-Dec-2024 11:31:31

1K+ Views

When working with databases in Java, there are scenarios where you might want to perform complex transactions involving multiple steps. To maintain control and flexibility during such operations, Savepoints come into play. The setSavepoint() method in the java.sql.Connection interface allows you to create a savepoint within a transaction, providing a mechanism to roll back to a specific point if needed. What is Savepoint? A Savepoint is a marker within a database transaction. It enables partial rollbacks, meaning you can undo a subset of changes made during a transaction without affecting the entire operation. This is particularly useful in scenarios where ... Read More

Java Connection getHoldability() method with example

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

361 Views

ResultSet holdability determines whether the ResultSet objects (cursors) should be closed or held open when a transaction (that contains the said cursor/ResultSet object) is committed using the commit() method of the Connection interface.The getHoldability() method of the Connection interface is used to retrieves and returns the current holdability value of the ResultSet objects in this connection.This method returns an integer value representing the current ResultSet holdability which will be either 1 or 2 where, 1 indicates the value HOLD_CURSORS_OVER_COMMIT.If the holdability of the ResultSet object is set to this value. Whenever you commit/save a transaction using the commit() method of the Connection ... Read More

Java Connection setHoldability() method with example

Revathi Satya Kondra
Updated on 30-Dec-2024 19:20:39

508 Views

ResultSet holdability determines whether the ResultSet objects (cursors) should be closed or held open when a transaction (that contains the said cursor/ ResultSet object) is committed using the commit() method of the Connection interface. The setHoldability() method of the Connection interface is used to set the holdability of the ResultSet objects in this connection (created using this connection) to a desired value. Syntax Following is the syntax of the Java Connection setHoldability() method − void setHoldability(int holdability) throws SQLException; Parameters This method accepts an integer value named "holdability", which is described below − Representing the ResultSet ... Read More

What is CLOSE_CURSORS_AT_COMMIT in JDBC?

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

518 Views

CLOSE_CURSORS_AT_COMMIT is the constant value of the ResultSet interface representing the holdability value. If the ResultSet holdability is set to this value whenever you commit/save a transaction using the commit() method of the Connection interface, the ResultSet objects created in the current transaction (that are already opened) will be closed.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 ... Read More

Advertisements