How To Store pdf or doc file in Oracle Database using Java Jdbc?

can any one help me out How To Store pdf or doc file in Oracle Database using Java Jdbc in JSP/Serlet? i tried like anything. using blob also i tried. but i am able 2 store images in DB not files. please if u know or else if u have some code like this plz send that to me, and help me out plz. i need that urgent.

Hi.. i am not getting error, But i am not getting the original contents from my file. i am getting all ASCII vales, instead of my original data. here i am including my code.
for Adding PDF in DB i used image.jsp
Database table structure (table name. pictures )
Name Null? Type
ID NOT NULL NUMBER(11)
IMAGE BLOB
<%@ page language="java" import="java.util.*,java.sql.*,java.io.*" pageEncoding="ISO-8859-1"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<%
try{
     Class.forName("oracle.jdbc.driver.OracleDriver");
     Connection con=DriverManager.getConnection("jdbc:oracle:thin:@192.168.1.135:1521:orcl","scott","tiger");
     PreparedStatement ps,pstmt,psmnt;
     ps = con.prepareStatement("INSERT INTO pictures VALUES(?,?)");
File file =
new File("D:/info.pdf");
FileInputStream fs = new FileInputStream(file);
ps.setInt(1,4);
ps.setBinaryStream(2,fs,fs.available());
int i = ps.executeUpdate();
if(i!=0){
out.println("<h2>PDF inserted successfully");
else{
out.println("<h2>Problem in image insertion");
catch(Exception e){
out.println("<h2>Failed Due To "+e);
%>
O/P: PDF inserted successfully
i tried to display that pdf using servlet. i am giving the code below.
import java.io.IOException;
import java.sql.*;
import java.io.*;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class DispPDF extends HttpServlet {
     * The doGet method of the servlet. <br>
     * This method is called when a form has its tag value method equals to get.
     * @param request the request send by the client to the server
     * @param response the response send by the server to the client
     * @throws ServletException if an error occurred
     * @throws IOException if an error occurred
     public void service(HttpServletRequest request, HttpServletResponse response)
               throws ServletException, IOException {
          //response.setContentType("text/html"); i commented. coz we cant use response two times.
          //PrintWriter out = response.getWriter();
          try{
               InputStream sPdf;
               Class.forName("oracle.jdbc.driver.OracleDriver");
                    Connection con=DriverManager.getConnection("jdbc:oracle:thin:@192.168.1.135:1521:orcl","scott","tiger");
                    PreparedStatement ps,pstmt,psmnt;
               psmnt = con.prepareStatement("SELECT image FROM pictures WHERE id = ?");
                    psmnt.setString(1, "4"); // here integer number '4' is image id from the table.
               ResultSet rs = psmnt.executeQuery();
                    if(rs.next()) {
               byte[] bytearray = new byte[1048576];
                    //out.println(bytearray);
                    int size=0;
                    sPdf = rs.getBinaryStream(1);
                    response.reset();
                    response.setContentType("application/pdf");
                    while((size=sPdf.read(bytearray))!= -1 ){
                    //out.println(size);
                    response.getOutputStream().write(bytearray,0,size);
               catch(Exception e){
               System.out.println("Failed Due To "+e);
                    //out.println("<h2>Failed Due To "+e);
          //out.close();
OP
PDF-1.4 %âãÏÓ 2 0 obj <>stream xœ+är á26S°00SIá2PÐ5´1ôÝ BÒ¸4Ü2‹ŠKüsSŠSŠS4C²€ê P”kø$V㙂GÒU×713CkW )(Ü endstream endobj 4 0 obj <>>>/MediaBox[0 0 595 842]>> endobj 1 0 obj <> endobj 3 0 obj <> endobj 5 0 obj <> endobj 6 0 obj <> endobj xref 0 7 0000000000 65535 f 0000000325 00000 n 0000000015 00000 n 0000000413 00000 n 0000000168 00000 n 0000000464 00000 n 0000000509 00000 n trailer <<01b2fa8b70ac262bfa939cc786f8770c>]/Root 5 0 R/Size 7/Info 6 0 R>> startxref 641 %%EOF
plz help me out.

Similar Messages

  • Saving a PDF or DOC file into Oracle 9i using Developer Forms 10g

    Hi guys,
    I want to save a pdf or doc file into oracle 9i. I am using Developer 10 g. Please help me;
    1. What datatype field should be in database table to store such file.
    2. Which code should I use in Forms 10g to display open file dialog, get the name and save that into database table.
    Thanks in advance

    WEBUTIL is a library used with forms to interact with the client. With Forms10G the library comes shipped with the developer suite, for forms 9i i'm not sure, check the forms-page at otn if there is any download available. For documentation about how to do a file-upload, simply search the forum, there are lots of examples.

  • How to store images in BLOB field in MySql database using java

    Hi....
    Currently am able to store character string into BLOB using byte array....in MySql.
    but i cannot store images or pictures.......
    to do this.........please help me out...............
    Thanx..........:)Bye...........

    Hello,
    I have done this for Oracle but it should be similar in MySQL also. Try reading thru these links below. Mail us if you have succeeded or not.
    http://forum.java.sun.com/thread.jspa?forumID=48&threadID=654086
    http://forum.java.sun.com/thread.jspa?forumID=48&threadID=384768
    http://forum.java.sun.com/thread.jspa?forumID=48&threadID=549705
    Thanks and regards,
    Pazhanikanthan. P

  • How to store xml data into file in xml format through java program?

    HI Friends,
    Please let me know
    How to store xml data into file in xml format through java program?
    thanks......
    can discuss further at messenger.....
    Avanish Kumar Singh
    Software Engineer,
    Samsung India Development Center,
    Bangalore--560001.
    [email protected]

    Hi i need to write the data from an XML file to a Microsoft SQL SErver database!
    i got a piece of code from the net which allows me to parse th file:
    import java.io.IOException;
    import org.xml.sax.*;
    import org.xml.sax.helpers.*;
    import org.apache.xerces.parsers.SAXParser;
    import java.lang.*;
    public class MySaxParser extends DefaultHandler
    private static int INDENT = 4;
    private static String attList = "";
    public static void main(String[] argv)
    if (argv.length != 1)
    System.out.println("Usage: java MySaxParser [URI]");
    System.exit(0);
    String uri = argv[0];
    try
    XMLReader parser = XMLReaderFactory.createXMLReader("org.apache.xerces.parsers.SAXParser");
    MySaxParser MySaxParserInstance = new MySaxParser();
    parser.setContentHandler(MySaxParserInstance);
    parser.parse(uri);
    catch(IOException ioe)
    ioe.printStackTrace();
    catch(SAXException saxe)
    saxe.printStackTrace();
    private int idx = 0;
    public void characters(char[] ch, int start, int length)
    throws SAXException
    String s = new String(ch, start, length);
    if (ch[0] == '\n')
    return;
    System.out.println(getIndent() + " Value: " + s);
    public void endDocument() throws SAXException
    idx -= INDENT;
    public void endElement(String uri, String localName, String qName) throws SAXException
    if (!attList.equals(""))
    System.out.println(getIndent() + " Attributes: " + attList);
    attList = "";
    System.out.println(getIndent() + "end document");
    idx -= INDENT;
    public void startDocument() throws SAXException
    idx += INDENT;
    public void startElement(String uri,
    String localName,
    String qName,
    Attributes attributes) throws SAXException
    idx += INDENT;
    System.out.println('\n' + getIndent() + "start element: " + localName);
    if (localName.compareTo("Machine") == 0)
    System.out.println("YES");
    if (attributes.getLength() > 0)
    idx += INDENT;
    for (int i = 0; i < attributes.getLength(); i++)
    attList = attList + attributes.getLocalName(i) + " = " + attributes.getValue(i);
    if (i < (attributes.getLength() - 1))
    attList = attList + ", ";
    idx-= INDENT;
    private String getIndent()
    StringBuffer sb = new StringBuffer();
    for (int i = 0; i < idx; i++)
    sb.append(" ");
    return sb.toString();
    }// END PRGM
    Now , am not a very good Java DEv. and i need to find a soln. to this prob within 1 week.
    The next step is to write the data to the DB.
    Am sending an example of my file:
    <Start>
    <Machine>
    <Hostname> IPCServer </Hostname>
    <HostID> 80c04499 </HostID>
    <MachineType> sun4u [ID 466748 kern.info] Sun Ultra 5/10 UPA/PCI (UltraSPARC-IIi 360MHz) </MachineType>
    <CPU> UltraSPARC-IIi at 360 MHz </CPU>
    <Memory> RAM : 512 MB </Memory>
    <HostAdapter>
    <HA> kern.info] </HA>
    </HostAdapter>
    <Harddisks>
    <HD>
    <HD1> c0t0d0 ctrl kern.info] target 0 lun 0 </HD1>
    <HD2> ST38420A 8.2 GB </HD2>
    </HD>
    </Harddisks>
    <GraphicCard> m64B : PCI PGX 8-bit +Accel. </GraphicCard>
    <NetworkType> hme0 : Fast-Ethernet </NetworkType>
    <EthernetAddress> 09:00:30:C1:34:90 </EthernetAddress>
    <IPAddress> 149.51.23.140 </IPAddress>
    </Machine>
    </Start>
    Note that i can have more than 1 machines (meaning that i have to loop thru the file to be able to write to the DB)
    Cal u tellme what to do!
    Even better- do u have a piece of code that will help me understand and implement the database writing portion?
    I badly need help here.
    THANX

  • How to insert data from *.dmp file to  oracle 11g using Oracle SQL Develope

    hi
    i backup my database using PL/SQL developer and made *.dmp file
    how to insert data from *.dmp file to oracle 11g using Oracle SQL Developer 2.1.1.64
    and how to make *.dmp file from sql*plus ?
    thanks in advance

    Pl/Sql developer has a config window, there you choose the exec to do the import/export.
    Find it and his home version, it may be exp or expdp, the home version is the version of the client where the exp executable is.
    Then use the same version of imp or impdp to execute the import, you do not need to use Oracle SQL Developer 2.1.1.64. If you want to use it, you must have the same version in the oracle home that exp/imp of sql developer use.

  • How to [b]store image[/b] in a [b]oracle database[/using [b]Visual Basic  ?

    I want to store an image (like jpg, bmp file) in a oracle Database using Visual Basic 6.0, Please Help me How can i do this.

    This url has a sample in VB which stores and retrieves images from database using VB
    http://otn.oracle.com/sample_code/tech/windows/ole_db/oledb8/content.html
    Chandar

  • Insert PDF or Doc file to the Database from Frontend

    Hi
    I am in ISB company working with Oracle 9iDS. The scenario is to me that I would like to insert some document files(especially Pdf formated files) to the database.
    I can use Read_Image_file. but that is used for the image file to bring the image file from physical location to my application, how it is for PDF?
    and how can i save it in the database?
    thanks
    farhad

    So are you saying you want to load a file from the pc/client to the database - then you can use webutil.
    see otn.oracle.com/products/forms
    Regards
    Grant Ronald
    Forms Product Management

  • How to Load Multiple Files in Oracle Database using Sql Loader

    Hi All,
    I want to import multiple files in my DB using Sql*Loader. Please tell me the Syntax, how can I import multiple files using one Control File?
    Thanks & Regards,
    Imran

    Hi,
    You might get a good response to your post in the forum dedicated to data movement , including SQL*Loader . You can find it here Export/Import/SQL Loader & External Tables
    Regards,

  • How to import a xls excel file to oracle database PL/SQL?

    Hello, im having some troubles to import a xls file to oracle, anyone knows a easy way or a script to import this file to database? thx!

    sure. this is the xls file View image: imagem1 and View image: imagem2
    and this is the code:
    DROP TABLE ext_table;
    create table ext_table (
    INFO varchar2(255),
    PRAZO varchar2(255),
    COD varchar2(255),
    CODIS varchar2(255),
    PRODUTO varchar2(255),
    VENDA_HTEC varchar2(10),
    PESO varchar2(255),
    TABELA varchar2(255),
    CUSTO varchar2(255),
    CUSTOPROD_ST varchar2(255),
    REAL varchar2(255),
    LC_V_P varchar2(255),
    IDEAL varchar2(255),
    ESTQ varchar2(255)
    organization external (
    type oracle_loader
    default directory d_extfile
    access parameters (
    records delimited by newline
    logfile 'ar.log'
    badfile 'ar.txt'
    fields terminated by ','
    missing field values are null
    location('TABELA_AUDIOGENE_HTEC_2012.xlsb')
    REJECT LIMIT unlimited;

  • How to get Operating System Space Info from Oracle database using SQL

    Our oracle databases are installed on Unix operating system. Currently our DBA wrote a view to get space info of table spaces and He is requesting me to add Operating system level(file system) drive space info to the same report.
    Can you please let me know the easiest way to get this information to sql table so that it can be used for reporting purposes?

    You should be able to create a shell script with the OS commands to generate the information for the mount points that you want to access in Oracle, then read it in as an external table using the preprocessor feature of external tables:
    http://download.oracle.com/otndocs/products/database/enterprise_edition/utilities/pdf/xtables_preproc11g_1009.pdf

  • Generate .dbf file from oracle database using JDBC

    Dear all,
    I need to generate a .dbf file from oracle table. Anyone know how to do this using Java Programming or JDBC? please help!
    thank you

    Hi,
    I assume you already have a JDBC driver for either FoxPro or DBase. If not, use the JDBC-ODBC bridge and the ODBC driver that comes with Window$.
    When you issue a "Create TABLE" command the driver will automatically create a .dbf file and then you can export data to it.
    Imran

  • How to align a raw Xml file tag by tag using java

    Hi All,
    Can any one please help me in writing a java code(jdk1.3) ,which will format a raw xml file and keep the formated data in a string object.

    Ex File:
    <POSBasket><Keyword>1|51|7|4116</Keyword><LastUpdated>2008-03-31T19:01:08+01:00</LastUpdated><MajorVersion>1</MajorVersion><MinorVersion>0</MinorVersion><BasketType>Sale</BasketType><State>Processed</State><Header><DateTimeCreated>2008-03-31T18:41:51+01:00</DateTimeCreated><OriginatedBy><DeviceID>ALL.MAT.51.TILL7</DeviceID><CashierID>051ROD</CashierID><CompanyID>1</CompanyID><StoreID>51</StoreID><BranchID>51</BranchID><TerminalNumber>7</TerminalNumber><TransactionNumber>4116</TransactionNumber></OriginatedBy><TaxMethodID>1</TaxMethodID><CustomerNumber>022578200260577</CustomerNumber><CustomerPan>022578200260577</CustomerPan><LoyaltyAccountNumber>022578200260577</LoyaltyAccountNumber><BasketLanguageID>en</BasketLanguageID><BasketCountryID>GB</BasketCountryID><BasketCurrencyID>GBP</BasketCurrencyID></Header></POSBasket>
    expected format:
    <POSBasket>
    <Keyword>1|51|7|4116</Keyword>
    <LastUpdated>2008-03-31T19:01:08+01:00</LastUpdated>
    <MajorVersion>1</MajorVersion>
    <MinorVersion>0</MinorVersion>
    <BasketType>Sale</BasketType>
    <State>Processed</State>
    <Header>
    <DateTimeCreated>2008-03-31T18:41:51+01:00</DateTimeCreated>
    <OriginatedBy>
    <DeviceID>ALL.MAT.51.TILL7</DeviceID>
    <CashierID>051ROD</CashierID>
    <CompanyID>1</CompanyID>
    <StoreID>51</StoreID>
    <BranchID>51</BranchID>
    <TerminalNumber>7</TerminalNumber>
    <TransactionNumber>4116</TransactionNumber>
    </OriginatedBy>
    <TaxMethodID>1</TaxMethodID>
    <CustomerNumber>022578200260577</CustomerNumber>
    <CustomerPan>022578200260577</CustomerPan>
    <LoyaltyAccountNumber>022578200260577</LoyaltyAccountNumber>
    <BasketLanguageID>en</BasketLanguageID>
    <BasketCountryID>GB</BasketCountryID>
    <BasketCurrencyID>GBP</BasketCurrencyID>
    </Header>
    </POSBasket>
    Can anyone help me on preparing logic using core java ???

  • How to store and retrieve .jpeg images from oracle database.

    I am using JSP. Can anybody tell me the process of doing it.

    I believe Oracle reccommends to use BLOBs for storing large binary data.
    Check on DBMS_LOB package on Oracle documentation: it has all the API's you
    need.

  • Storing pdf document as pages in oracle 9i using java

    hi
    When pdf doc is gets uploaded it needs to be saved to the db by pages
    (Ex. if a doc. has 2 pages 2 records need to be saved to db).
    Client should be able to download several documents at once or several pages of the certain document.

    And your question is?
    http://www.lowagie.com/iText/
    http://java.sun.com/docs/books/tutorial/jdbc/index.html

  • Upload pdf file in oracle database

    Hi Everyone,
    Can anybody describe me that how to upload/download pdf or doc file into oracle database using oracle form10g?
    Thanks in Advance.
    Baloch.

    Hello,
    The Webutil library has a FILE_TRANSFER package that includes functions to transfer file between the client machine, the Application Server and the Database.
    Francois

Maybe you are looking for

  • HP 6520 wifi won't connect

    Just took a 6520 out of the box, trying to set it up/print to it from a windows 8.1 computer, after returning a 4620 printer that had the same problem. Ran the setup software. Setup software can't even manage to figure out what wireless network the c

  • Where is the software for the Lenovo G550???

    I want to do a clean install and replace the pre-installed Vista with Windows 7. I see that the Lenovo G550 download page has drivers for Windows 7, but where is the pre-installed software, like Veriface, camera software, and all other pre-installed

  • Documents/Commentary

    Hi everyone, We would like to implement a solution which provides them with the functionality to add Commentary and Annotations to BW Reports when they enter data manually via BPS and to have these documents displayed inline with the web report. SEM/

  • Blackberry apps wont work !!

     okay so basically i have the bible app and facebook app.Bought were working GREAT ! until..... out of no were they stoped working it keeps saying "you dont have enough sufficient wireless coverage or your wifi is turned off " which its not my wifi i

  • Not able to connect wifi from personal hotspot

    When switch "on" Personal Hotspot on my ipad mini wifi + cellular, I'm not able to connect wifi from my iphone even from other devices. Please advice!!