Found 4219 Articles for MySQLi

What is JDBC Blob data type? how to store and read data from it?

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

10K+ Views

A BLOB is binary large object that can hold a variable amount of data with a maximum length of 65535 characters.These are used to store large amounts of binary data, such as images or other types of files. Fields defined as TEXT also hold large amounts of data. The difference between the two is that the sorts and comparisons on the stored data are case sensitive on BLOBs and are not case sensitive in TEXT fields. You do not specify a length with BLOB or TEXT.Storing blob in to databaseTo store Blob datatype to database, using JDBC program follow the ... Read More

What are the data types supported by JDBC?

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

188 Views

JDBC provides support for almost all the SQL datatypes Whenever the JDBC driver receives a call from a Java application it converts the Java datatypes in it to the corresponding SQL data types. The conversion process follows default mapping. Following is the list of data types supported by JDBC and their corresponding SQL datatypes.SQLJDBC/JavaVARCHARjava.lang.StringCHARjava.lang.StringLONGVARCHARjava.lang.StringBITbooleanNUMERICjava.math.BigDecimalTINYINTbyteSMALLINTshortINTEGERintBIGINTlongREALfloatFLOATfloatDOUBLEdoubleVARBINARYbyte[ ]BINARYbyte[ ]DATEjava.sql.DateTIMEjava.sql.TimeTIMESTAMPjava.sql.TimestampCLOBjava.sql.ClobBLOBjava.sql.BlobARRAYjava.sql.ArrayREFjava.sql.RefSTRUCTjava.sql.Struct

What is the use of setFetchSize() and setMaxRows() methods of the JDBC Statement Interface?

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

1K+ Views

The setFetchSize(int) method defines the number of rows that will be read from the database when the ResultSet needs more rows. setFetchSize(int) affects how the database returns the ResultSet data.Whereas, setMaxRows(int) method of the ResultSet specifies how many rows a ResultSet can contain at a time. setMaxRows(int) affects the client side JDBC object.

What is the difference between the methods setBlob() and setBinaryStream() which is preferable in JDBC?

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

681 Views

The setBlob() method is used to set value for Blob datatype in the database. It has three variants as follows:void setBlob(int parameterIndex, Blob x): Sets the given Blob value to the parameter at the specified index.void setBlob(int parameterIndex, InputStream inputStream): Sets the contents of the given input stream as a value to the parameter at the specified index.void setBlob(int parameterIndex, InputStream inputStream, long length): Sets the contents of the given input stream as a value to the parameter at the specified index.The setBinaryStream() method is used to set the contents of the given InputStream as a value for the parameter ... Read More

How to insert an image in to MySQL database using Java program?

Nancy Den
Updated on 31-Oct-2023 04:08:56

23K+ Views

To hold an image in MySQL database generally blob type is used. Therefore, make sure that you have a table created with a blob datatype with the following description:+-------+--------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +-------+--------------+------+-----+---------+-------+ | Name | varchar(255) | YES | | NULL | | | image | blob | YES | | NULL | | +-------+--------------+------+-----+---------+-------+To insert an image in to MySQL database, follow the steps given below:Step 1: Connect to the databaseYou can connect to a database using the getConnection() method of the DriverManager class.Connect to the MySQL database ... Read More

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

227 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

247 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

Advertisements