SEO Software
Closed Thread
Results 1 to 2 of 2

Thread: Insert & Retrive file from Mysql

  1. #1

    Default Insert & Retrive file from Mysql

    I want to insert & retrive image & textfile into Mysql Database.
    How to do it?


  2. Micro Niche Builder

  3. #2

    Default may be it will help you.

    public boolean storeImg()
    throws Exception
    {
    boolean written = false;
    //opening db
    Class.forName(dbDriver);
    ConrsIn = DriverManager.getConnection(dburl,dbUser,dbPasswor t);


    if (ConrsIn == null)
    written = false;
    else
    {
    try
    {
    Stmtrsext = ConrsIn.createStatement();
    //int intID = rsext.getInt("id");

    // ******* <BLOB> **********

    file = new File(PICTURE);
    fis = new FileInputStream(file);
    ps = ConrsIn.prepareStatement("insert into PICTURE values (?,?)");

    // ***use as many ??? as you need to insert in the exact order!!!!*** ps.setString(1,file.getName());
    ps.setBinaryStream(2,fis,(int)file.length());
    ps.executeUpdate();
    ps.close();
    fis.close();

    // ****** </BLOB> ******

    written = true;
    }
    catch (SQLException E)
    {
    written = false;
    System.out.println("SQLException: " + E.getMessage());
    System.out.println("SQLState: " + E.getSQLState());
    System.out.println("VendorError: " + E.getErrorCode());
    }
    }
    //close db conn
    //rsIn.close();
    ConrsIn.close();
    return written;
    }

    this should do! just need to insert your values (also don't know how you open your db con! important for the blob-img storage is the part in between ***BLOB****!!!

Closed Thread

Similar Threads

  1. Mysql Trigger
    By sanky12ka4 in forum Databases
    Replies: 0
    Last Post: 09-02-2009, 02:53 PM
  2. PHP and mysql backup
    By valendino in forum PHP Help
    Replies: 0
    Last Post: 08-25-2009, 09:36 AM
  3. OOPS - MySQL
    By gilbertsavier in forum Databases
    Replies: 0
    Last Post: 08-05-2009, 11:19 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts