title: Convert String into Blob
body: <p>I'm new to JDBC and stack overflow as well, and what I'm trying to do here is this :</p>
  
  <p>I'm trying to insert a string as blob into a database but I'm getting null pointer exception. Here is the code I'm using :</p>
  
  <pre><code>public String execute() {
      String success="Success";
      try{
          Class.forName("com.mysql.jdbc.Driver");
          Connection con = DriverManager.getConnection("jdbc:mysql://panorama-pc:3306/sample", "sample", "sample123");
          String sql = "Insert into users values(?,?,?,?,?)";
          PreparedStatement ps = con.prepareStatement(sql);
          ps.setNull(1, Types.NULL);  
          ps.setString(2,name);
          ps.setString(3,RollNo);
          ps.setString(4, date);
  
          Blob blob = con.createBlob();
  
          blob.setBytes(1,desc.getBytes()); // getting exception here 
  
          int i = ps.executeUpdate();
          if(i&gt;0){
              return SUCCESS;
          }
          else{
              return ERROR;
          }
      }
      catch(SQLException | ClassNotFoundException e){
          e.printStackTrace();
      }       
  </code></pre>
  
  <p>Here desc is a string and I'm trying to insert it into a blob column. Can someone please help me out ? </p>