Results 1 to 3 of 3
  1. #1
    sks
    sks is offline Member
    Join Date
    Mar 2011
    Location
    malaysia
    Posts
    9
    Rep Power
    0

    Default How to upload .txt file to mysql using JDBC

    Hi all,
    Please help me how to upload .txt file to mysql. the parameter in sql is BLOB.
    Do i need to save the file in my local disk first then query the file to sql?
    or mayb u can suggest any link for me....

    thanks in advance

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,755
    Rep Power
    19

    Default

    You have a stream for the uploaded file, just use that in the insert query (setBinaryStream() in PreparedStatement). No need to go via disk.

  3. #3
    UJJAL DHAR is offline Senior Member
    Join Date
    Apr 2010
    Location
    Dhaka,Bangladesh
    Posts
    180
    Rep Power
    0

    Default

    BLOB is not needed.You can make a table with a single field parameter TEXT.And you can upload a .text from your desktop on it using FILE class .
    Java Code:
           String fileName ="C:/insert.txt";
           File file = new File(fileName);
           FileInputStream fis = new FileInputStream(file);
           pstmt = conn.prepareStatement("insert into tablename(columnname) values (?)");
         
          pstmt.setAsciiStream(1, fis, (int) file.length());
          pstmt.executeUpdate();
    Don't Forget to try yourself before asking others help.....
    Press REP, if you find their advices/solutions effective.

Similar Threads

  1. JDBC MySql question
    By santa in forum New To Java
    Replies: 12
    Last Post: 01-18-2011, 03:47 PM
  2. com.mysql.jdbc.Driver
    By uthpalaw in forum Eclipse
    Replies: 2
    Last Post: 10-14-2010, 05:09 AM
  3. :large file upload to server(chunk upload)
    By tommy_725 in forum Networking
    Replies: 0
    Last Post: 10-16-2009, 12:21 AM
  4. MySQL/JDBC Mysql query output
    By thelinuxguy in forum Advanced Java
    Replies: 4
    Last Post: 02-13-2009, 01:57 AM
  5. help ... JDBC or PHP/MySQL
    By bluebarca in forum Advanced Java
    Replies: 1
    Last Post: 11-16-2007, 10:05 AM

Posting Permissions

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