Found 317 Articles for JDBC

Java Connection The setClientInfo() method with example

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

615 Views

The setClientInfo() method of the Connection interface sets values to the client info properties of the current connection object.ParametersThis method accepts a Properties object as a parameter.con.setClientInfo(properties);To set values to the client info properties file.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 using the getConnection() method of the DriverManager class as −//Getting the connection String url = "jdbc:mysql://localhost/mydatabase"; Connection con = DriverManager.getConnection(url, "root", "password");Create a properties object as −Properties properties = new Properties();Add the required key-value pairs to the above created Properties object as −properties.put("user_name", "new_user"); properties.put("password", "password");Set the above created ... Read More

How to establish a connection with the database using the properties file in JDBC?

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

1K+ Views

One of the variant of the getConnection() method of the DriverManager class accepts url of the database, (String format) a properties file and establishes connection with the database.Connection con = DriverManager.getConnection(url, properties);To establish a connection with a database using this method −Set the Driver class name as a system property −System.setProperty("Jdbc.drivers", "com.mysql.jdbc.Driver");Create a properties object as −Properties properties = new Properties();Add the user name and password to the above created Properties object as −properties.put("user", "root"); properties.put("password", "password");Finally invoke the getConnection() method of the DriverManager class by passing the URL and, properties object as parameters.//Getting the connection String url = "jdbc:mysql://localhost/mydatabase"; Connection con = ... Read More

Java Connection getMetaData() method with example

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

1K+ 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 name of the database, version, driver name, user name and, 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 database.To get ... Read More

Java Connection getCatalog() method with example

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

690 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

3K+ 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 30-Jul-2019 22:30:26

493 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.The getAutocommit() method of the Connection interface is used to get the current value of the auto-commit in this connection.To get the auto-commit value −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 using the getConnection() method of the DriverManager class as −//Getting the connection String url = "jdbc:mysql://localhost/mydatabase"; Connection con ... Read More

Java Connection releaseSavepoint() method with example

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

253 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

3K+ 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

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

498 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 save point using the rollback() method.You can set a save point in a database using the setSavepoint(String savepointName) method of the Connection interface.//Setting the save point Savepoint savePoint = con.setSavepoint("MysavePoint");This method accepts a string value representing the name of the save point and, returns a save point object.To set a save point −Register the driver using the registerDriver() method of the DriverManager class as −//Registering ... Read More

Java Connection getHoldability() method with example

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

172 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

Advertisements