Found 317 Articles for JDBC

How to drop a database using JDBC API?

Nitya Raut
Updated on 30-Jul-2019 22:30:25

203 Views

A. You can drop/delete a database using the DROP DATABASE query.SyntaxDROP DATABASE DatabaseName;To drop 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 object using the createStatement() method of the Connection interface.Execute the Query: Execute the query using the execute() method of the Statement interface.ExampleThe show databases command gives ... Read More

How to select or, shift to another database in MySQL using a JDBC API?

Vrundesha Joshi
Updated on 30-Jul-2019 22:30:25

338 Views

In general, You can change the current database in MySQL using the USE query.SyntaxUse DatabaseName;To change the current 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 object using the createStatement() method of the Connection interface.Execute the Query: Execute the query using the execute() method of the Statement interface.ExampleFollowing JDBC ... Read More

How to create a database in MySQL using a JDBC API?

Jennifer Nicholas
Updated on 30-Jul-2019 22:30:25

2K+ Views

A. In general, you can create a database using the CREATE DATABASE query.SyntaxCREATE DATABASE DatabaseName;To create 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 object using the createStatement() method of the Connection interface.Execute the Query: Execute the query using the execute() method of the Statement interface.Example:Following JDBC program ... Read More

How to insert rows into a ResultSet in JDBC?

Nancy Den
Updated on 30-Jul-2019 22:30:25

807 Views

You can retrieve the contents of a table as a ResultSet and, insert a new row to it directly. To do so, first of all, you need to make sure your ResultSet is updatable.The moveToInsertRow() method of the ResultSet interface navigates the cursor to the position where you need to insert the next record. Therefore, move the cursor to the appropriate position to insert a row using this method.The updateXXX() methods of the ResultSet interface allows you to insert/update values into the ResultSet object.Add values to the new row using these methods for example if you need to insert an ... Read More

What are batch updates in JDBC? Explain?

Nancy Den
Updated on 30-Jul-2019 22:30:25

816 Views

Grouping a set of INSERT or, UPDATE or, DELETE commands (those produce update count value) and execute them at once this mechanism is known as a batch update.Adding statements to the batchThe statement, PreparedStatement, and CallableStatement objects hold a list (of commands) to which you can add related statements (those return update count value) using the addBatch() method.stmt.addBatch(insert1); stmt.addBatch(insert2); stmt.addBatch(insert3);Executing the batchAfter adding the required statements, you can execute a batch using the executeBatch() method of the Statement interface.stmt.executeBatch();Using batch updates, we can reduce the communication overhead and increase the performance of our Java application.Note: Before adding statements to the ... Read More

What are connected and disconnected Row Sets in JDBC?

Krantik Chavan
Updated on 30-Jul-2019 22:30:25

334 Views

A RowSet is a wrapper around a ResultSet Object. It can be connected, disconnected from the database and can be serialized. It maintains a JavaBean component by setting the properties. You can pass a RowSet object over the network. By default, the RowSet object is scrollable and updatable.A RowSet Object is of two typesConnected Row Sets: A connected RowSet object connects to the database using a JDBC driver. It establishes a connection with the database and, carries out the required operations. The connection is maintained until the RowSet object is closed.Disconnected Row Sets: A disconnected RowSet object connects to the ... Read More

What is CONCUR_READ_ONLY ResultSet in JDBC? Explain?

Krantik Chavan
Updated on 30-Jul-2019 22:30:25

2K+ Views

In general, you will pass this as a value to the createStatement() method as a value of ResultSet Concurrency type.Statement createStatement(int resultSetType, int resultSetConcurrency)This type of result set is not updatable. i.e. once you get a ResultSet object you cannot update its contents.ExampleSuppose, we have a table named Employee in the database with the following contents:+----+---------+--------+----------------+ | Id | Name    | Salary | Location       | +----+---------+--------+----------------+ | 1  | Amit    | 3000   | Hyderabad      | | 2  | Kalyan  | 4000   | Vishakhapatnam | | 3  | Renuka  | 6000   ... Read More

What is CONCUR_UPDATABLE ResultSet in JDBC? Explain?

Krantik Chavan
Updated on 30-Jul-2019 22:30:25

2K+ Views

It is a constant of the ResultSet class representing the concurrency mode for a ResultSet object that may be updated. In general, you will pass this as a value to the createStatement() method.Statement createStatement(int resultSetType, int resultSetConcurrency);A ResultSet with this as concurrency is updatable. i.e. once you get a ResultSet object you can update its contents.ExampleSuppose, we have a table named Employee in the database with the following contents:+----+---------+--------+----------------+ | Id | Name    | Salary | Location       | +----+---------+--------+----------------+ | 1  | Amit    | 3000   | Hyderabad      | | 2  | Kalyan  | ... Read More

What is ResultSet Concurrency in JDBC?

Krantik Chavan
Updated on 30-Jul-2019 22:30:25

1K+ Views

The concurrency of the ResultSet object determines whether its contents can be updated or not.The Connection interface provides 3 variants of the createStatement() method where one of the method's signature is as follows:Statement createStatement(int resultSetType, int resultSetConcurrency)This method accepts two integer type variables where one represents the type of the ResultSet and the other represents the Concurrency of the ResultSet.The ResultSet interface provides two values to specify the concurrency of the ResultSet.CONCUR_READ_ONLY: If you set this as a value of the concurrency while creating the ResultSet object you cannot update the contents of the ResultSet you can only read/retrieve them.CONCUR_UPDATABLE: ... Read More

What is the difference between the TYPE_SCROLL_INSENSITIVE and TYPE_SCROLL_SENSITIVE ResultSets in JDBC?

Krantik Chavan
Updated on 30-Jul-2019 22:30:25

1K+ Views

In the TYPE_SCROLL_INSENSITIVE ResultSet, the cursor moves in forward or backward directions. This type of ResultSet is insensitive to the changes that are made in the database i.e. the modifications done in the database are not reflected in the ResultSet.Which means if we have established a connection with a database using a JDBC program and retrieved a ResultSet holding all the records in a table named SampleTable. Meanwhile, if we have added some more records to the table (after retrieving getting the ResultSet), these recent changes will not be reflected in the ResultSet object we previously obtained.In the TYPE_SCROLL_SENSITIVE ResultSet, ... Read More

Advertisements