Retrieve image from database in java

PreparedStatement provides the facility to store and retrieve the images in the database using JDBC. PreparedStatement methods to retrieve image: public Blob getBlob(int columnIndex) throws SQLException  Example: JDBCTest.java import java.io.FileOutputStream; import java.sql.Blob; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import com.w3schools.util.JDBCUtil;   /** * This class is used to retrieve a image from DB. * @author w3schools */ public … Read more

Store image in database in java

PreparedStatement provides the facility to store and retrieve the images in the database using JDBC. PreparedStatement methods to store image: 1. public void setBinaryStream(int paramIndex,InputStream stream)  throws SQLException  2. public void setBinaryStream(int paramIndex,InputStream stream,long length)  throws SQLException  Example: JDBCTest.java import java.io.FileInputStream; import java.sql.Connection; import java.sql.PreparedStatement; import com.w3schools.util.JDBCUtil;   /** * This class is used to store a image in DB. * @author w3schools */ public class … Read more

Retrieve file from database in java

PreparedStatement provides the facility to store and retrieve the file in the database using JDBC. PreparedStatement methods to retrieve file: 1. public Clob getClob(int columnIndex) throws SQLException Example: JDBCTest.java import java.io.FileWriter; import java.io.Reader; import java.sql.Clob; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet;   import com.w3schools.util.JDBCUtil;   /** * This class is used to retrieve a file … Read more

Store file in database using JDBC

PreparedStatement provides the facility to store and retrieve the file in the database using JDBC. PreparedStatement methods to store file: 1. public void setBinaryStream(int paramIndex,InputStream stream)   throws SQLException  2. public void setBinaryStream(int paramIndex,InputStream stream,long length)  throws SQLException   Example: JDBCTest.java import java.io.File; import java.io.FileReader; import java.sql.Connection; import java.sql.PreparedStatement; import com.w3schools.util.JDBCUtil;   /** * This class is used to store a file in DB. * @author w3schools */ … Read more

JDBC CallableStatement Stored procedure batch update

The JDBC CallableStatement is used to execute the store procedure and functions. Let us study JDBC CallableStatement by batch update example. Example: insertEMPLOYEE Procedure JDBC CallableStatement Stored procedure IN parameter example. CREATE OR REPLACE PROCEDURE insertEMPLOYEE( e_id IN EMPLOYEE.EMPLOYEE_ID%TYPE, e_name IN EMPLOYEE.NAME%TYPE, e_salary IN EMPLOYEE.SALARY%TYPE) IS BEGIN   INSERT INTO EMPLOYEE ("EMPLOYEE_ID", "NAME", "SALARY") VALUES … Read more

JDBC CallableStatement Stored procedure OUT parameter

The JDBC CallableStatement is used to execute the store procedure and functions. Let us study JDBC CallableStatement by OUT parameter example. Example: getEmpNameByEmpId Procedure JDBC CallableStatement Stored procedure IN parameter example. CREATE OR REPLACE PROCEDURE getEmpNameByEmpId( e_id IN EMPLOYEE.EMPLOYEE_ID%TYPE, e_NAME OUT EMPLOYEE.NAME%TYPE) IS BEGIN   SELECT NAME INTO e_NAME FROM EMPLOYEE WHERE EMPLOYEE_ID = e_id; … Read more

JDBC CallableStatement Stored procedure IN parameter example

The JDBC CallableStatement is used to execute the store procedure and functions. Let us study JDBC CallableStatement by IN parameter example. Example: insertEMPLOYEE Procedure JDBC CallableStatement Stored procedure IN parameter example. CREATE OR REPLACE PROCEDURE insertEMPLOYEE( e_id IN EMPLOYEE.EMPLOYEE_ID%TYPE, e_name IN EMPLOYEE.NAME%TYPE, e_salary IN EMPLOYEE.SALARY%TYPE) IS BEGIN   INSERT INTO EMPLOYEE ("EMPLOYEE_ID", "NAME", "SALARY") VALUES … Read more

JDBC CallableStatement interface

The JDBC CallableStatement is used to execute the store procedure and functions. CallableStatement interface provides the methods to execute the store procedure and functions. We can get a statement object by invoking the prepareCall() method of Connection interface. Syntax: CallableStatement callableStatement = conn.prepareCall(“{call procedurename(?,?…?)}”);  Note: A store procedure is used to perform business logic and … Read more

Batch update using PreparedStatement JDBC

The JDBC PreparedStatement is used to execute parameterized queries against the database. Let us study JDBC PreparedStatement by batch update example. Example: JDBCTest.java import java.sql.Connection; import java.sql.PreparedStatement; import com.w3schools.util.JDBCUtil;   /** * This class is used to batch update in DB table * using PreparedStatement. * @author w3schools */ public class JDBCTest { public static … Read more

Delete record using PreparedStatement JDBC

The JDBC PreparedStatement is used to execute parameterized queries against the database. Let us study JDBC PreparedStatement by deletes a record example. Example: JDBCTest.java import java.sql.Connection; import java.sql.PreparedStatement; import com.w3schools.util.JDBCUtil;   /** * This class is used to delete a record from DB table * using PreparedStatement. * @author w3schools */ public class JDBCTest { … Read more