Found 6702 Articles for Database

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

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

10K+ Views

CLOB stands for Character Large Object in general, an SQL Clob is a built-in datatype and is used to store large amount of textual data. Using this datatype, you can store data up to 2, 147, 483, 647 characters.The java.sql.Clob interface of the JDBC API represents the CLOB datatype. Since the Clob object in JDBC is implemented using an SQL locator, it holds a logical pointer to the SQL CLOB (not the data).MYSQL database provides support for this datatype using four variables.TINYTEXT: A CLOB type with a maximum of 28-1 (255) characters.TEXT: A CLOB type with a maximum of 216-1 ... Read More

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

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

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

192 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

696 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

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

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

5K+ Views

To hold an image in Oracle database generally blob type is used. Therefore, make sure that you have a table created with a blob datatype as:Name Null? Type ----------------------------------------- -------- ---------------------------- NAME VARCHAR2(255) IMAGE BLOBTo insert an image in to Oracle database, follow the steps given below:Step 1: Connect to the databaseYou can connect to a database using the getConnection() method of the DriverManager classConnect to the Oracle database by passing the Oracle URL which is jdbc:oracle:thin:@localhost:1521/xe (for express edition), username and password as parameters to the getConnection() method.String oracleUrl = "jdbc:oracle:thin:@localhost:1521/xe"; Connection con = DriverManager.getConnection(oracleUrl, "user_name", "password");Step 2: Create ... 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

231 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

Advertisements