As blob.sql convert to String



  • There's a conclusion from the JDBC database, and there's a code on it.

                       str += ("[" +
                        "'" + rs.getInt("ID") + "', " +
                        "'" + rs.getString("NAME") + "',  " +
                        "'" + rs.getString("TYPE") + "',  " +
                        "'" + rs.getString("DATA") + "', " +
                        "'" + rs.getBlob("MESSAGE") + "', " +
                        "'" + rs.getInt("ID2") + "', " +
                        "'" + rs.getString("NAMEDOCUMENT") + "', " +
                        "'" + rs.getInt("ID1") + "', " +
                        "'" + rs.getString("STATUS") +
                        "'],");
    

    Field Message I'm like bloband when I take it to Ext JS that value Does he have a reference to the object as to convert what would matter to Ext JS?



  • BLOB (binary large object) is the dual data of the unspecialized format. It's not very clear why you have Message (probably textual) stored as BLOB♪ For large text data, a type shall be used CLOB (actcharer large object).

    If you want to get the contents out. BLOB, interpreting it as a text, you need to know what code this text was in. Let's say, UTF-8♪ Then you can do this:

    // ограничим максимальную длину блока данных, чтобы память не кончилась
    int LENGTH_LIMIT = 100_000; 
    Blob blob = rs.getBlob("MESSAGE");
    long length = blob.length();
    // а лучше кидать исключение, если неожиданно слишком большая длина
    if(length > LENGTH_LIMIT) length = LENGTH_LIMIT;
    byte[] data = blob.getBytes(0, (int)length);
    String message = new String(data, StandardCharsets.UTF_8);
    // теперь используйте message
    

    In conclusion, it is very bad to form JSON with the content of lines. You're gonna get a lot on the first single skirt inside the text. There's a lot of ready libraries to do it quickly and safely.




Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2