name text
department_id bigint
Department Master
id bigint
name text
INNER JOIN department_master dept ONemployee.department_id=dept.id
package org.in.my.data; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.SQLException; public class DBConnection { public void connect() { try { Class.forName("org.postgresql.Driver"); } catch (ClassNotFoundException e) { e.printStackTrace(); } Connection connection = null; try { connection = DriverManager.getConnection( "jdbc:postgresql://localhost:5432/testing", "postgres", "postgres"); File file = new File("d:\\samnew.pdf"); FileInputStream fis = new FileInputStream(file); fis.close(); InputStream is = null; StringBuffer out = null; ResultSet rs = connection.createStatement().executeQuery( "SELECT filedata FROM documents where id=1"); byte[] imgBytes = null; if (rs != null) { while (rs.next()) { imgBytes = rs.getBytes(1); } FileOutputStream os = new FileOutputStream("d:\\samoutput.pdf"); os.write(imgBytes); os.flush(); os.close(); } rs.close(); connection.close(); } catch (SQLException e) { e.printStackTrace(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } }If you have tried the example and it is not working. If the file size is double the original size, Then execute the below command in postgres database and then try again