• Thursday , 14 December 2017

Java JDBC Tutorial – Part 10: BLOB – Reading and Writing BLOB with MySQL

Code Canyon



NEED TO LEARN JAVA? – 5 FREE JAVA VIDEO COURSES – CLICK HERE – https://goo.gl/7i95F8 — View more videos on my “Java JDBC Tutorial” Playlist: …

Original source

3d Ocean

Related Posts

30 Comments

  1. Bilal Tasdemir
    September 27, 2017 at 10:55

    Hello
    I insert .pdf documents in my database. But when I want to view this pdf, I see some meaningless letters.No problem for .txt documents.I can view .txt documents .How can I deal with this problem?Could you help me please ?

  2. shokhrukh suvanov
    September 27, 2017 at 10:55

    Hello
    I sent an email which was about writing blob in Java, If you have time, Could you please check?  Thanks

  3. Silent ass
    September 27, 2017 at 10:55

    I got the error, " Invalid escape sequence (valid ones are b t n f r " ' \ )"
    when specifying the complete path to the sample_resume file… can u tell me how to resolve this?

  4. Ruqaiya Kurawadwala
    September 27, 2017 at 10:55

    hey , how to read the blob from the mysql database and and then display it in a jframe? is it possible?

  5. Syed Zeeshan Ali
    September 27, 2017 at 10:55

    hey, nice video. Very helpful for me.
    sir instead of storing the file into the local system, how can we show that file directly from the database onto the JSP page??
    Sir plz help me.
    Thank you in advanced.

  6. Adam Ellgood
    September 27, 2017 at 10:55

    Hey, great video! This has really helped me with understanding the concept of uploading and retrieving files from a database. Thankyou

    I am trying to make it graphical where a user logged in can select the file they wish to upload to the database.

    I imagine I would have to allow the user to identify their self through a username into a text field. I imagine I need the user to identify the absolute file path? That way on a button, the user will write their file to their record in the database.

    How can I go about doing this? Any chance of some guidance and/or source code?

    Thanks again, Adam.

  7. Violet Anderson
    September 27, 2017 at 10:55

    Very very very useful! Thanks a bunch!

  8. Angelo De Bruyne
    September 27, 2017 at 10:55

    You've got the best tutorials! Really good work 🙂

  9. Hasta Nobel
    September 27, 2017 at 10:55

    verry, verry, verry, thank you

  10. Hasta Nobel
    September 27, 2017 at 10:55

    thankz bro, verry helpfull

  11. enio marku
    September 27, 2017 at 10:55

    Hi Chad,

    I really appreciate your videos. I am a professional oracle java certified but anyway you are much better than me so i need your advice . Actually i am developing a protocol and in this protocol we need to take files read it one by one and each file byte by byte and for each byte of the file we perform one algorithm . This works good and i have tried it with folder in my pc where there are some files in it . Now my boss wanted for me to try this in amazon cloud and i am wondering how can i do it in amazon since i have no idea how amazon is working. Is it good idea if i just upload my folder in amazon and then run my application or is better to use their databases with some files in it let say 5 images and try to read and write the files from their databases? Actually i am not even sure what kind of databases they use but for sure not mysql since mysql is for small companies but i also doubt if they are using any kind of database which is compatible with jdbc. Please give me a clue what to do with this amazon cloud

  12. Datutos knoQ
    September 27, 2017 at 10:55

    very very very tank you guy
    you are a genius

  13. The Aman
    September 27, 2017 at 10:55

    Hello chad. While I execute the program, then it completed successfully but the problem while i open the value in editor at workbench then it doesn't show the image tab there… so can u pls help me

  14. Filip Nedovic
    September 27, 2017 at 10:55

    Program works the same with direct writing to file from ResultSet with getBytes function -> out.write(rs.getBytes("resume"));,
    without this peace of code:
    InputStream in = rs.getBinaryStream("reusme");

    byte[] buffer = new byte[1024];

    if(in.read(buffer)>0) {
    out.write(buffer);
    }

    Q: Is there a specific reason why you do this with peace of code above?

  15. Giuseppe Canto
    September 27, 2017 at 10:55

    Hi, thank you for sharing this content with a lesson so smoothly.

  16. Junior Silva
    September 27, 2017 at 10:55

    Professor, I'm also getting the ' java.io.FileNotFoundException: sample_resume.pdf (No such file or directory)' exception

    Is this what I have to do to fix it in the Java code?

    File file = new File("/Users/juniorsilva/Desktop/sample_resume.pdf");

    That's the path to my Mac desktop…

  17. My Kill Cruz
    September 27, 2017 at 10:55

    is it possible to store audio files with the size of up 10mb in mysqldatabase??

  18. Ralph Manzano
    September 27, 2017 at 10:55

    there is no image tab in my editor in sql, and in the text tab all i see are (C/DD^,n~;>RâæQø^¥*Ï ) somewhat like these characters, what am i doing wrong?

  19. Oleg Kaluzny
    September 27, 2017 at 10:55

    Thanks for ur all videos .. im getting exception…

    Reading input file: D:sample_resume.pdf

    Storing resume in database: D:sample_resume.pdf
    update employees set resume=? where email='jon.doe@foo.com'
    com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown column 'resume' in 'field list'
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
    at java.lang.reflect.Constructor.newInstance(Unknown Source)
    at com.mysql.jdbc.Util.handleNewInstance(Util.java:404)
    at com.mysql.jdbc.Util.getInstance(Util.java:387)
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:939)
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3878)
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3814)
    at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2478)
    at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2625)
    at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2551)
    at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1861)
    at com.mysql.jdbc.PreparedStatement.executeUpdateInternal(PreparedStatement.java:2073)
    at com.mysql.jdbc.PreparedStatement.executeUpdateInternal(PreparedStatement.java:2009)
    at com.mysql.jdbc.PreparedStatement.executeLargeUpdate(PreparedStatement.java:5094)
    at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1994)
    at BlobsAndClobs.WriteBlobDemo.main(WriteBlobDemo.java:45)

  20. Christopher Ware
    September 27, 2017 at 10:55

    I appreciate the tutorial. Would I be able to tailor reading and writing BLOBs to SQLite using your general format? I've always been a bit slow with Java. Thank you.

  21. Common Yunus
    September 27, 2017 at 10:55

    Champion!

  22. Sohel Ahmed
    September 27, 2017 at 10:55

    What can I do to handle this Situation

    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
    at com.mysql.jdbc.Util.handleNewInstance(Util.java:404)
    at com.mysql.jdbc.Util.getInstance(Util.java:387)
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:939)
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3878)
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3814)
    at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2478)
    at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2625)
    at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2551)
    at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1861)
    at com.mysql.jdbc.PreparedStatement.executeUpdateInternal(PreparedStatement.java:2073)
    at com.mysql.jdbc.PreparedStatement.executeUpdateInternal(PreparedStatement.java:2009)
    at com.mysql.jdbc.PreparedStatement.executeLargeUpdate(PreparedStatement.java:5094)
    at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1994)
    at WriteBlobDemo.main(WriteBlobDemo.java:32)

  23. sayan mandal
    September 27, 2017 at 10:55

    Hi , this is a very good tutorial! however I am unable to see the value of blob in mysql workbench….There is Text and binary tab but there is no image tab.please can you help me solve the problem?

  24. Quốc Tuyền Trần
    September 27, 2017 at 10:55

    Thank you very much 🙂

  25. T Prasanna
    September 27, 2017 at 10:55

    Thanks for ur all videos .. im getting exception lyk ==> java.io.FileNotFoundException: sample_resume.pdf(The system cannot find the file specified
    at java.io.FileInputStream.open(Native Method)
    at java.io.FileInputStream.<init> (FileInputStream.java:146)
    at jdbcdemo.WriteBlob.main (WriteBlobDemo.java: 36)

  26. Ravinder Battula
    September 27, 2017 at 10:55

    Hi,

    Thanks for your videos. I am getting error and it says Data is too long for column 'resume' . The pdf file size is just 333KB only.
    I have to mention the file name including C drive ( complete path), otherwise it gives an error. Would you please let me know where it went wrong. Thanks.

    File theFile = new File("c:\data\RAVINDER.pdf");

    Output:

    Reading input file: c:dataRAVINDER.pdf

    Storing resume in database: c:dataRAVINDER.pdf
    update employees set resume=? where email='john.doe@foo.com'
    com.mysql.jdbc.MysqlDataTruncation: Data truncation: Data too long for column 'resume' at row 1
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3868)

  27. Tấn Đạt Nguyễn
    September 27, 2017 at 10:55

    Hello guys, your video is good but I have 2 questions and hope that you can help me.
    1. Is pdf file same as blob file ?
    2. How can we stream the content pdf file directly to web browser ? This pdf have already stored in the database.
    Anyways, thank you very much!

  28. John Francis Bonifacio
    September 27, 2017 at 10:55

    the code works uploading the file. but how can i directly open it in one click in my system gui?

  29. kaoutar Elmoh
    September 27, 2017 at 10:55

    I want to give the user the possibility to choose his file . how can I do that ?

  30. Palak Kashyap
    September 27, 2017 at 10:55

    how do I change the path to which the file is being saved? I mean can I mention it explicitly rather than having the program decide the path

Leave A Comment

You must be logged in to post a comment.