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




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


30 responses to “Java JDBC Tutorial – Part 10: BLOB – Reading and Writing BLOB with MySQL”

  1. 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. 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.

  3. 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

  4. 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

  5. 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?

  6. 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…

  7. 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)

  8. 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)

  9. 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)

  10. 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)

  11. 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!

Leave a Reply