Photo Insert and Retrieve App
package com.nt.photo
importjava.io.File;
importjava.io.FileInputStream;
importjava.sql.DriverManager;
importjava.sql.PreparedStatement;
importjava.sql.Connection;
importjava.sql.SQLException;
publicclass PhotoInsert{
publicstaticvoidmain(String[] args) throwsException{
try{
//registerjdbcdriver
Class.forName("oracle.jdbc.driver.OracleDriver");
System.out.println("Driverclassloadedsuccessfully....");
// establishconnection
Connectioncon=(Connection)
DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:orcl","system","password");
System.out.println("ConnectionCreatedSuccessfully....");
//create PreparedStatementobject
PreparedStatementps=con.prepareStatement("insertintoempallvalues(?,?,?,?)");
//setthe valuestothe field
ps.setInt(1,234);
ps.setString(2,"Durga");
ps.setFloat(3,1400);
File f=newFile("C:UsersARTIFICIALPicturesACHIEVERSLOGOFINAL1.jpg");
System.out.println(f);
FileInputStreamfis=newFileInputStream(f);//FileInputStreamcommunicatesviafile object
System.out.println(fis);
ps.setBinaryStream(4,fis,(int)f.length());
//execute the query
ps.executeUpdate();
System.out.println("PhotoInserted");
//close the jdbcobject
fis.close();
ps.close();
con.close();
}
catch(ClassNotFoundExceptione)
{
System.out.println("DriverclassNotloadedsuccessfully....");
} catch (SQLExceptione) {
// TODO Auto-generatedcatchblock
e.printStackTrace();
}
}//main
}//class
Photo Retrieve codes
package com.nt.photo
import java.io.FileOutputStream;
import java.io.InputStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
public class PhotoRetrieve {
public static void main(String[] args) throws Exception{
try{
//register the driver and establish connection
Class.forName("oracle.jdbc.driver.OracleDriver");
System.out.println("Driver loaded Succecssfully.... ");
Connection
con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:152
1:orcl","system","password");
System.out.println("Connection created successfully.....");
//create JDBC Statement obj
Statement st= con.createStatement();
//execute the sql Query
ResultSet rs=st.executeQuery("select * from empall");
//process the ResultSet object
if(rs.next()){
System.out.println(rs.getInt(1));
//get the input stream pointing to Blob value of ResultSet
InputStream in=rs.getBinaryStream("ephoto");
System.out.println(in);
//output Stream pointing to destination file
FileOutputStream fos=new
FileOutputStream("C:UsersARTIFICIALPicturesACHIEVERS
FINAL.jpg");
System.out.println(fos);
//buffering based logic to complete photo retrieving
int bytesRead=0;//counter variable
byte[] buffer= new byte[4096];//buffer
while((bytesRead=in.read(buffer))!=-1)//bytesRead holds the data
of buffer
{
fos.write(buffer,0,bytesRead); //0 is start position of buffer
and bytesRead is end position of buffer...
}
System.out.println("photo retrieved and send to the
destination..");
//close jdbc objects
fos.close();
in.close();
rs.close();
con.close();
}//if
}
catch(Exception e){
e.printStackTrace();
}
}//main
}//class

More Related Content

PPTX
Spring boot for buidling microservices
PDF
Step By Step Guide For Buidling Simple Struts App
PDF
스프링 시큐리티로 시작하는 웹 어플리케이션 보안
PDF
JavaFX Pitfalls
PDF
How to create a skeleton of a Java console application
PDF
Struts tutorial
PDF
Catalyst patterns-yapc-eu-2016
PDF
Spring mvc my Faviourite Slide
Spring boot for buidling microservices
Step By Step Guide For Buidling Simple Struts App
스프링 시큐리티로 시작하는 웹 어플리케이션 보안
JavaFX Pitfalls
How to create a skeleton of a Java console application
Struts tutorial
Catalyst patterns-yapc-eu-2016
Spring mvc my Faviourite Slide

What's hot (20)

DOCX
Oracle Application Framework
PPTX
Springboot2 postgresql-jpa-hibernate-crud-example
PDF
Drupal8Day: Demystifying Drupal 8 Ajax Callback commands
PPT
Mobicents JSLEE progress and roadmap - Mobicents Summit 2011
PDF
Spring Boot Actuator
PDF
Jetpack, with new features in 2021 GDG Georgetown IO Extended
PPTX
Introduction to Spring Boot
PPTX
Integrating Security Roles into Microsoft Silverlight Applications
PDF
Building an app with Google's new suites
DOCX
Pom
PPTX
Spring boot Introduction
PPTX
Spring Boot
PPTX
Protractor framework architecture with example
PPTX
Testy integracyjne
PDF
스프링 시큐리티로 시작하는 웹 어플리케이션 보안 _강사준비 스터디 버전
PDF
#30.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)_스프링프레임워크 강좌, 재직자환급교육,실업자국비지원...
DOCX
Servlet LifeCycle Demo App
PPTX
Christophe Spring Actionscript Flex Java Exchange
PDF
Introduction to Spring Boot
Oracle Application Framework
Springboot2 postgresql-jpa-hibernate-crud-example
Drupal8Day: Demystifying Drupal 8 Ajax Callback commands
Mobicents JSLEE progress and roadmap - Mobicents Summit 2011
Spring Boot Actuator
Jetpack, with new features in 2021 GDG Georgetown IO Extended
Introduction to Spring Boot
Integrating Security Roles into Microsoft Silverlight Applications
Building an app with Google's new suites
Pom
Spring boot Introduction
Spring Boot
Protractor framework architecture with example
Testy integracyjne
스프링 시큐리티로 시작하는 웹 어플리케이션 보안 _강사준비 스터디 버전
#30.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)_스프링프레임워크 강좌, 재직자환급교육,실업자국비지원...
Servlet LifeCycle Demo App
Christophe Spring Actionscript Flex Java Exchange
Introduction to Spring Boot
Ad

Viewers also liked (20)

PPTX
System obiegu korespondencji
PDF
الاستئناف بداية نهاية الشلل التاريخي - أبو يعرب المرزوقي
PDF
الإستئناف بداية نهاية الشلل التاريخي - أبو يعرب المرزوقي
DOCX
Scrollable Test App
PPTX
Domaine des finets
PPTX
Diapositivas Info
PPTX
Digipak Layout
PPTX
Part up - crowd-resource your projects
DOCX
Online Form Submission App
DOCX
TextSearch
DOCX
Transaction Management Tool
PDF
Konferencja Intratic Przyjazny SharePoint, Maciej Pondel, Adam Dolega - Co no...
DOCX
Net Beans Codes for Student Portal
PDF
What's On @ Pickering Public Library Jan - May 2014
DOCX
Multiple Submit Button Test App
DOCX
Scrollable Demo App
PDF
Msk imaging adult hip pain j griffith
DOCX
PPTX
Enterprise content management i digital workplace. Fundamenty dla
PPTX
1st draft Digipak
System obiegu korespondencji
الاستئناف بداية نهاية الشلل التاريخي - أبو يعرب المرزوقي
الإستئناف بداية نهاية الشلل التاريخي - أبو يعرب المرزوقي
Scrollable Test App
Domaine des finets
Diapositivas Info
Digipak Layout
Part up - crowd-resource your projects
Online Form Submission App
TextSearch
Transaction Management Tool
Konferencja Intratic Przyjazny SharePoint, Maciej Pondel, Adam Dolega - Co no...
Net Beans Codes for Student Portal
What's On @ Pickering Public Library Jan - May 2014
Multiple Submit Button Test App
Scrollable Demo App
Msk imaging adult hip pain j griffith
Enterprise content management i digital workplace. Fundamenty dla
1st draft Digipak
Ad

Similar to Photo Insert and Retrieve App (9)

PPT
30 5 Database Jdbc
PDF
I really need help on this question.Create a program that allows t.pdf
PPT
Data Access with JDBC
PPT
PPT
Executing Sql Commands
PPT
Executing Sql Commands
PPS
Jdbc example program with access and MySql
PDF
M.TECH 1ST SEM COMPUTER SCIENCE ADBMS LAB PROGRAMS
PDF
PHP Data Objects
30 5 Database Jdbc
I really need help on this question.Create a program that allows t.pdf
Data Access with JDBC
Executing Sql Commands
Executing Sql Commands
Jdbc example program with access and MySql
M.TECH 1ST SEM COMPUTER SCIENCE ADBMS LAB PROGRAMS
PHP Data Objects

Photo Insert and Retrieve App

  • 1. Photo Insert and Retrieve App package com.nt.photo importjava.io.File; importjava.io.FileInputStream; importjava.sql.DriverManager; importjava.sql.PreparedStatement; importjava.sql.Connection; importjava.sql.SQLException; publicclass PhotoInsert{ publicstaticvoidmain(String[] args) throwsException{ try{ //registerjdbcdriver Class.forName("oracle.jdbc.driver.OracleDriver"); System.out.println("Driverclassloadedsuccessfully...."); // establishconnection Connectioncon=(Connection) DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:orcl","system","password"); System.out.println("ConnectionCreatedSuccessfully...."); //create PreparedStatementobject PreparedStatementps=con.prepareStatement("insertintoempallvalues(?,?,?,?)"); //setthe valuestothe field ps.setInt(1,234); ps.setString(2,"Durga"); ps.setFloat(3,1400);
  • 2. File f=newFile("C:UsersARTIFICIALPicturesACHIEVERSLOGOFINAL1.jpg"); System.out.println(f); FileInputStreamfis=newFileInputStream(f);//FileInputStreamcommunicatesviafile object System.out.println(fis); ps.setBinaryStream(4,fis,(int)f.length()); //execute the query ps.executeUpdate(); System.out.println("PhotoInserted"); //close the jdbcobject fis.close(); ps.close(); con.close(); } catch(ClassNotFoundExceptione) { System.out.println("DriverclassNotloadedsuccessfully...."); } catch (SQLExceptione) { // TODO Auto-generatedcatchblock e.printStackTrace(); } }//main }//class
  • 3. Photo Retrieve codes package com.nt.photo import java.io.FileOutputStream; import java.io.InputStream; import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.Statement; public class PhotoRetrieve { public static void main(String[] args) throws Exception{ try{ //register the driver and establish connection Class.forName("oracle.jdbc.driver.OracleDriver"); System.out.println("Driver loaded Succecssfully.... "); Connection con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:152 1:orcl","system","password"); System.out.println("Connection created successfully.....");
  • 4. //create JDBC Statement obj Statement st= con.createStatement(); //execute the sql Query ResultSet rs=st.executeQuery("select * from empall"); //process the ResultSet object if(rs.next()){ System.out.println(rs.getInt(1)); //get the input stream pointing to Blob value of ResultSet InputStream in=rs.getBinaryStream("ephoto"); System.out.println(in); //output Stream pointing to destination file FileOutputStream fos=new FileOutputStream("C:UsersARTIFICIALPicturesACHIEVERS FINAL.jpg"); System.out.println(fos); //buffering based logic to complete photo retrieving
  • 5. int bytesRead=0;//counter variable byte[] buffer= new byte[4096];//buffer while((bytesRead=in.read(buffer))!=-1)//bytesRead holds the data of buffer { fos.write(buffer,0,bytesRead); //0 is start position of buffer and bytesRead is end position of buffer... } System.out.println("photo retrieved and send to the destination.."); //close jdbc objects fos.close(); in.close(); rs.close(); con.close(); }//if } catch(Exception e){