Java JDBC Tutorial – Part 11: CLOB – Reading and Writing CLOB 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


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

  1. hello luv2code , I am getting following exception:Exception in thread "main" java.io.FileNotFoundException: New Text Document.txt (The system cannot find the file specified)Could you please tell me where we suppose to store file in local drive?

  2. Hello ,

    I wrote this simple code to read from blob file in the database and write to a local file .
    it creates a local file but it doesn't write on it , i don't know what i miss.

    __________________________________

    import java.io.*;
    import java.sql.*;

    public class ClobsWriteFileToDB {

    public static void main(String[] args) {

    String url = "jdbc:mysql://localhost:3306/testschema";
    String user = "root";
    String pass = "isoft123";
    try {
    Class.forName("com.mysql.jdbc.Driver").newInstance();
    Connection myConn = DriverManager.getConnection(url, user, pass);

    String sql = "select cv from test where id=2";

    Statement myStmt = myConn.createStatement();

    ResultSet myRs = myStmt.executeQuery(sql);

    File theFile = new File("outPutSamlple.txt");
    FileWriter output = new FileWriter(theFile);

    if (myRs.next()) {

    Reader input = myRs.getCharacterStream("cv");
    int theChar;
    while ((theChar = input.read()) > 0) {
    output.write(theChar);
    }
    }

    } catch (Exception e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }

    }

    }

Leave a Reply