Program: 47306
Project: 47306
Buggy source:
public synchronized void insertData(String name,long modified,int type,DLNAMediaInfo media){
  Connection conn=null;
  PreparedStatement ps=null;
  try {
    conn=getConnection();
    ps=conn.prepareStatement("String_Node_Str");
    ps.setString(1,name);
    ps.setTimestamp(2,new Timestamp(modified));
    ps.setInt(3,type);
    if (media != null) {
      if (media.getDuration() != null) {
        ps.setDouble(4,media.getDurationInSeconds());
      }
 else {
        ps.setNull(4,Types.DOUBLE);
      }
      ps.setInt(5,media.getBitrate());
      ps.setInt(6,media.getWidth());
      ps.setInt(7,media.getHeight());
      ps.setLong(8,media.getSize());
      ps.setString(9,truncate(media.getCodecV(),SIZE_CODECV));
      ps.setString(10,truncate(media.getFrameRate(),SIZE_FRAMERATE));
      ps.setString(11,truncate(media.getAspect(),SIZE_ASPECT));
      ps.setInt(12,media.getBitsPerPixel());
      ps.setBytes(13,media.getThumb());
      ps.setString(14,truncate(media.getContainer(),SIZE_CONTAINER));
      if (media.getExtras() != null) {
        ps.setString(15,truncate(media.getExtrasAsString(),SIZE_MODEL));
      }
 else {
        ps.setString(15,truncate(media.getModel(),SIZE_MODEL));
      }
      ps.setInt(16,media.getExposure());
      ps.setInt(17,media.getOrientation());
      ps.setInt(18,media.getIso());
      ps.setString(19,truncate(media.getMuxingModeAudio(),SIZE_MUXINGMODE));
      ps.setString(20,truncate(media.getFrameRateMode(),SIZE_FRAMERATE_MODE));
    }
 else {
      ps.setString(4,null);
      ps.setInt(5,0);
      ps.setInt(6,0);
      ps.setInt(7,0);
      ps.setLong(8,0);
      ps.setString(9,null);
      ps.setString(10,null);
      ps.setString(11,null);
      ps.setInt(12,0);
      ps.setBytes(13,null);
      ps.setString(14,null);
      ps.setString(15,null);
      ps.setInt(16,0);
      ps.setInt(17,0);
      ps.setInt(18,0);
      ps.setString(19,null);
      ps.setString(20,null);
    }
    ps.executeUpdate();
    ResultSet rs=ps.getGeneratedKeys();
    int id=-1;
    while (rs.next()) {
      id=rs.getInt(1);
    }
    rs.close();
    if (media != null && id > -1) {
      PreparedStatement insert=null;
      if (media.getAudioTracksList().size() > 0) {
        insert=conn.prepareStatement("String_Node_Str");
      }
      for (      DLNAMediaAudio audio : media.getAudioTracksList()) {
        insert.clearParameters();
        insert.setInt(1,id);
        insert.setInt(2,audio.getId());
        insert.setString(3,truncate(audio.getLang(),SIZE_LANG));
        insert.setString(4,truncate(audio.getFlavor(),SIZE_FLAVOR));
        insert.setInt(5,audio.getAudioProperties().getNumberOfChannels());
        insert.setString(6,truncate(audio.getSampleFrequency(),SIZE_SAMPLEFREQ));
        insert.setString(7,truncate(audio.getCodecA(),SIZE_CODECA));
        insert.setInt(8,audio.getBitsperSample());
        insert.setString(9,truncate(StringUtils.trimToEmpty(audio.getAlbum()),SIZE_ALBUM));
        insert.setString(10,truncate(StringUtils.trimToEmpty(audio.getArtist()),SIZE_ARTIST));
        insert.setString(11,truncate(StringUtils.trimToEmpty(audio.getSongname()),SIZE_SONGNAME));
        insert.setString(12,truncate(StringUtils.trimToEmpty(audio.getGenre()),SIZE_GENRE));
        insert.setInt(13,audio.getYear());
        insert.setInt(14,audio.getTrack());
        insert.setInt(15,audio.getAudioProperties().getAudioDelay());
        insert.setString(16,truncate(StringUtils.trimToEmpty(audio.getMuxingModeAudio()),SIZE_MUXINGMODE));
        insert.setInt(17,audio.getBitRate());
        insert.executeUpdate();
      }
      if (media.getSubtitleTracksList().size() > 0) {
        insert=conn.prepareStatement("String_Node_Str");
      }
      for (      DLNAMediaSubtitle sub : media.getSubtitleTracksList()) {
        if (sub.getExternalFile() == null) {
          insert.clearParameters();
          insert.setInt(1,id);
          insert.setInt(2,sub.getId());
          insert.setString(3,truncate(sub.getLang(),SIZE_LANG));
          insert.setString(4,truncate(sub.getFlavor(),SIZE_FLAVOR));
          insert.setInt(5,sub.getType().ordinal());
          insert.executeUpdate();
        }
      }
      close(insert);
    }
  }
 catch (  SQLException se) {
    if (se.getMessage().contains("String_Node_Str")) {
      LOGGER.debug("String_Node_Str" + name + "String_Node_Str"+ se.getMessage());
    }
 else {
      LOGGER.error(null,se);
    }
  }
 finally {
    close(ps);
    close(conn);
  }
}

Fixed version (ground truth):
public synchronized void insertData(String name,long modified,int type,DLNAMediaInfo media){
  Connection conn=null;
  PreparedStatement ps=null;
  try {
    conn=getConnection();
    ps=conn.prepareStatement("String_Node_Str");
    ps.setString(1,name);
    ps.setTimestamp(2,new Timestamp(modified));
    ps.setInt(3,type);
    if (media != null) {
      if (media.getDuration() != null) {
        ps.setDouble(4,media.getDurationInSeconds());
      }
 else {
        ps.setNull(4,Types.DOUBLE);
      }
      ps.setInt(5,media.getBitrate());
      ps.setInt(6,media.getWidth());
      ps.setInt(7,media.getHeight());
      ps.setLong(8,media.getSize());
      ps.setString(9,left(media.getCodecV(),SIZE_CODECV));
      ps.setString(10,left(media.getFrameRate(),SIZE_FRAMERATE));
      ps.setString(11,left(media.getAspect(),SIZE_ASPECT));
      ps.setInt(12,media.getBitsPerPixel());
      ps.setBytes(13,media.getThumb());
      ps.setString(14,left(media.getContainer(),SIZE_CONTAINER));
      if (media.getExtras() != null) {
        ps.setString(15,left(media.getExtrasAsString(),SIZE_MODEL));
      }
 else {
        ps.setString(15,left(media.getModel(),SIZE_MODEL));
      }
      ps.setInt(16,media.getExposure());
      ps.setInt(17,media.getOrientation());
      ps.setInt(18,media.getIso());
      ps.setString(19,left(media.getMuxingModeAudio(),SIZE_MUXINGMODE));
      ps.setString(20,left(media.getFrameRateMode(),SIZE_FRAMERATE_MODE));
    }
 else {
      ps.setString(4,null);
      ps.setInt(5,0);
      ps.setInt(6,0);
      ps.setInt(7,0);
      ps.setLong(8,0);
      ps.setString(9,null);
      ps.setString(10,null);
      ps.setString(11,null);
      ps.setInt(12,0);
      ps.setBytes(13,null);
      ps.setString(14,null);
      ps.setString(15,null);
      ps.setInt(16,0);
      ps.setInt(17,0);
      ps.setInt(18,0);
      ps.setString(19,null);
      ps.setString(20,null);
    }
    ps.executeUpdate();
    ResultSet rs=ps.getGeneratedKeys();
    int id=-1;
    while (rs.next()) {
      id=rs.getInt(1);
    }
    rs.close();
    if (media != null && id > -1) {
      PreparedStatement insert=null;
      if (media.getAudioTracksList().size() > 0) {
        insert=conn.prepareStatement("String_Node_Str");
      }
      for (      DLNAMediaAudio audio : media.getAudioTracksList()) {
        insert.clearParameters();
        insert.setInt(1,id);
        insert.setInt(2,audio.getId());
        insert.setString(3,left(audio.getLang(),SIZE_LANG));
        insert.setString(4,left(audio.getFlavor(),SIZE_FLAVOR));
        insert.setInt(5,audio.getAudioProperties().getNumberOfChannels());
        insert.setString(6,left(audio.getSampleFrequency(),SIZE_SAMPLEFREQ));
        insert.setString(7,left(audio.getCodecA(),SIZE_CODECA));
        insert.setInt(8,audio.getBitsperSample());
        insert.setString(9,left(trimToEmpty(audio.getAlbum()),SIZE_ALBUM));
        insert.setString(10,left(trimToEmpty(audio.getArtist()),SIZE_ARTIST));
        insert.setString(11,left(trimToEmpty(audio.getSongname()),SIZE_SONGNAME));
        insert.setString(12,left(trimToEmpty(audio.getGenre()),SIZE_GENRE));
        insert.setInt(13,audio.getYear());
        insert.setInt(14,audio.getTrack());
        insert.setInt(15,audio.getAudioProperties().getAudioDelay());
        insert.setString(16,left(trimToEmpty(audio.getMuxingModeAudio()),SIZE_MUXINGMODE));
        insert.setInt(17,audio.getBitRate());
        insert.executeUpdate();
      }
      if (media.getSubtitleTracksList().size() > 0) {
        insert=conn.prepareStatement("String_Node_Str");
      }
      for (      DLNAMediaSubtitle sub : media.getSubtitleTracksList()) {
        if (sub.getExternalFile() == null) {
          insert.clearParameters();
          insert.setInt(1,id);
          insert.setInt(2,sub.getId());
          insert.setString(3,left(sub.getLang(),SIZE_LANG));
          insert.setString(4,left(sub.getFlavor(),SIZE_FLAVOR));
          insert.setInt(5,sub.getType().ordinal());
          insert.executeUpdate();
        }
      }
      close(insert);
    }
  }
 catch (  SQLException se) {
    if (se.getMessage().contains("String_Node_Str")) {
      LOGGER.debug("String_Node_Str" + name + "String_Node_Str"+ se.getMessage());
    }
 else {
      LOGGER.error(null,se);
    }
  }
 finally {
    close(ps);
    close(conn);
  }
}