Found 317 Articles for JDBC

Write an JDBC example for inserting value for Blob datatype into a table?

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

2K+ Views

Assume we already have a table named MyTable in the database with the following description.+-------+--------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +-------+--------------+------+-----+---------+-------+ | Name | varchar(255) | YES | | NULL | | | image | blob | YES | | NULL | | +-------+--------------+------+-----+---------+-------+If you need to ... Read More

How to insert images in Database using JDBC?

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

4K+ Views

The setBinaryStream() method of the PreparedStatement interface accepts an integer representing the index of the parameter and an InputStream object and sets the parameter to the given InputStream object. Whenever you need to send very large binary value you can use this method.And SQL databases provide a datatype named Blob (Binary Large Object) in this you can store large binary data like images.Storing image using JDBCIf you need to store an image in a database using the JDBC program create a table with a Blob datatype as shown below:CREATE TABLE Tutorial(Name VARCHAR(255), Type INT NOT NULL, Logo BLOB);Now, using JDBC, connect ... Read More

What are save points in JDBC? Explain?

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

198 Views

Savepoint interface gives you the additional transactional control. Most modern DBMS, support save points within their environments such as Oracle's PL/SQL.When you set a save point you define a logical rollback point within a transaction. If an error occurs past a save point, you can use the rollback method to undo either all the changes or only the changes made after the save point.The Connection object has two new methods that help you manage save points −setSavepoint(String savepointName): Defines a new save point. It also returns a Savepoint object.releaseSavepoint(Savepoint savepointName): Deletes a Savepoint. Notice that it requires a Savepoint object ... Read More

What are the methods provided by the ResultSet to navigate through it in JDBC?

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

226 Views

We have two types of ResultSet objects namely, forward Only and, bi-directional as the names suggest you can move in only one direction (forward) in forward only ResultSet and, in bidirectional ResultSet you can move the pointer in both directions. The ResultSet interface provides several methods to navigate through both types of ResultSet objects.Following table lists various methods to navigate through ResultSet object.MethodDescriptionnext()This method moves the resultset pointer one row forward.Previous() This method moves the resultset pointer one row backward.first()This method moves the resultset pointer to the first row.last()This method moves the resultset pointer to the last row.relative()This method accepts an ... Read More

What is JDBC SQL Escape Syntax Explain?

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

1K+ Views

The escape syntax gives you the flexibility to use database specific features unavailable to you by using standard JDBC methods and properties.The general SQL escape syntax format is as follow:{keyword 'parameters'}Following are various escape syntaxes in JDBC:d, t, ts Keywords: They help identify date, time, and timestamp literals. As you know, no two DBMSs represent time and date the same way. This escape syntax tells the driver to render the date or time in the target database's format{d 'yyyy-mm-dd'}Where yyyy = year, mm = month; dd = date. Using this syntax {d '2009-09-03'} is March 9, 2009.Example//Create a Statement object ... Read More

How to update the contents of a ResultSet using a JDBC program?

Daniol Thomas
Updated on 30-Jul-2019 22:30:25

79 Views

To update the contents of the ResultSet you need to create a statement by passing the ResultSet type updatable, as://Creating a Statement object Statement stmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);Just like getXXX() and setXXX() methods ResultSet interface also provides methods to update the contents of a row in a result set updateXXX().These methods accept integer values representing the index or, a String value representing the column label, of the row to be updated.Note that if you need to update the contents of a ResultSet the table should have a primary key.ExampleAssume we have a table named Employees with 5 records as shown ... Read More

What is a RowSet object explain using a JDBC program?

Daniol Thomas
Updated on 30-Jul-2019 22:30:25

208 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, RowSet object is scrollable and updatable and it is used to make a ResultSet object scrollable and updatable.You Can get a RowSet using theRowSetProvider.newFactory().createJdbcRowSet() method.ExampleAssume we have a table named dataset in the database as:+--------------+-----------+ | mobile_brand | unit_sale | +--------------+-----------+ | Iphone       |      3000 | | Samsung      |      4000 ... Read More

What are the advantages of stored procedures?

Daniol Thomas
Updated on 30-Jul-2019 22:30:25

3K+ Views

Following are the advantages of stored procedures:Since stored procedures are compiled and stored, whenever you call a procedure the response is quick.you can group all the required SQL statements in a procedure and execute them at once.Since procedures are stored on the database server which is faster than client. You can execute all the complicated quires using it, which will be faster.Using procedures, you can avoid repetition of code moreover with these you can use additional SQL functionalities like calling stored functions.Once you compile a stored procedure you can use it in any number of applications. If any changes are ... Read More

Explain the difference between RowSet and ResultSet in JDBC?

Daniol Thomas
Updated on 09-Mar-2020 06:42:48

2K+ Views

Following are the differences between RowSet and ResultSet:ResultSetRowSetA ResultSet always maintains connection with the database.A RowSet can be connected, disconnected from the database.It cannot be serialized.A RowSet object can be serialized.ResultSet object cannot be passed other over network.You can pass a RowSet object over the network.ResultSet object is not a JavaBean objectYou can create/get a result set using the executeQuery() method.ResultSet Object is a JavaBean object.You can get a RowSet using the RowSetProvider.newFactory().createJdb cRowSet() method.By default, ResultSet object is not scrollable or, updatable.By default, RowSet object is scrollable and updatable.Read More

How to Navigate through a ResultSet using a JDBC program?

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

139 Views

The next() method of the ResultSet interface moves the pointer/Cursor of the current ResultSet object to the next row from the current position. This method returns a boolean value. If there are no rows next to its current position this method returns false, else it returns true.Therefore, using this method in the while loop you can iterate the contents of the ResultSet object.while(rs.next()){ }Getting the column values of each recordThe ResultSet interface (also) provides getter methods (getXXX()) to retrieve values in each column of a row, each getter methods has two variants:getXXX(int columnIndex): Accepts an integer value representing the index ... Read More

Advertisements