Results 1 to 2 of 2

Thread: plsql

  1. #1
    Junior Member
    Join Date
    Mar 2006
    Answers
    1

    plsql

    how to insert a music file into the database


  2. #2
    Junior Member
    Join Date
    Mar 2006
    Answers
    2

    Re: plsql

    ---------------


    ******************************************************************************
    Uploading File
    ******************************************************************************

    Taking the file from Request and store it in LocalD Drive
    ---------------------------------------------------------
    MultipartParser multipart = new MultipartParser(request,10000024);
    File file=null;
    File mkd=null;
    Part p = null;
    int i=0;
    while(true) {
    p = multipart.readNextPart();
    if((p!=null)&&(p.isFile()))
    {
    mkd=new File("c:/uploaded");
    mkd.mkdirs();
    part = (FilePart)p;
    file = new File(mkd+"/"+part.getFileName());
    part.writeTo(file);
    break;
    }
    }
    FileInputStream fis = new FileInputStream(file);



    Storing in Database
    -------------------
    PreparedStatement ps = con.prepareStatement(insertQuery);
    ps.setBinaryStream(1,fis,(int)file.length());

    ******************************************************************************
    Downloading File
    ******************************************************************************

    put this code in doGet() or doPost() Method
    -------------------------------------------
    Hashtable hash= new Hashtable();
    hash.put("html","application/html");
    hash.put("htm","application/html");
    hash.put("txt","application/text");
    hash.put("doc","application/msword");
    hash.put("ppt","application/vnd.ms-powerpoint");
    hash.put("xls","application/vnd.ms-excel");
    hash.put("bin","application/octet-stream");
    hash.put("exe","application/octet-stream");
    hash.put("zip","application/zip");
    hash.put("jpg","application/jpeg");
    hash.put("gif","application/gif");
    hash.put("jpeg","application/jpeg");
    hash.put("pdf","application/adobe");
    hash.put("js","application/javascript");
    hash.put("bmp","application/bmp");
    hash.put("eml","application/outlook");
    hash.put("xml","application/XML");
    hash.put("css","application/CSS");

    PreparedStatement pstmt=con.prepareStatement(sql);
    pstmt.setInt(1,Integer.parseInt(fileid));
    ResultSet rs = pstmt.executeQuery();

    while(rs.next())
    {
    filename = rs.getString(4);
    filetype = filename.substring(filename.indexOf(".")+1,filename.length());
    if (hash.get(filetype)!=null) {
    response.setContentType((String)hash.get(filetype));
    response.setHeader("Content-Disposition","Attachment; Filename="+filename);
    }
    sos = response.getOutputStream();
    Blob blb = (Blob)rs.getObject(3);
    byte[] mybuf = blb.getBytes(3,(int)blb.length());
    InputStream inStream = blb.getBinaryStream();
    byte[] jbuffer = new byte[10]; // buffer holding bytes to be transferred
    int nbytes = 0; // Number of bytes read
    long totalsize = 0;
    while( (nbytes = inStream.read(jbuffer)) != -1 )
    {
    // Read from Blob stream
    sos.write(jbuffer,0,nbytes);
    totalsize += nbytes;
    }
    }


    --------------------------------------------


    u can upload anytype of file and download the same even with the above code.....try out..


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
About us
Applying for a job can be a stressful and frustrating experience, especially for someone who has never done it before. Considering that you are competing for the position with a at least a dozen other applicants, it is imperative that you thoroughly prepare for the job interview, in order to stand a good chance of getting hired. That's where GeekInterview can help.
Interact