10 thoughts on “Java JDBC Tutorial – Part 11: CLOB – Reading and Writing CLOB with MySQL

  • February 11, 2019 at 19:41
    Permalink

    For people, who will not download the source code. When you try to read CLOB, keep in mind that you have to close the writer:

    writer.close();

  • February 11, 2019 at 19:41
    Permalink

    hi. thank you for your videos 🙂
    Could you tell me how to get rid of this kind of excepton
    java.sql.SQLException: Incorrect string value: 'xEFxBBxBFFUC.. ?

  • February 11, 2019 at 19:41
    Permalink

    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?

  • February 11, 2019 at 19:41
    Permalink

    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