public RecordWriter getRecordWriter(TaskAttemptContext context)
          throws IOException {
    Configuration conf = context.getConfiguration();
    String tableName = getQualifiedTableName(conf);

    if (tableName == null || tableName.isEmpty()) {
      throw new IllegalArgumentException("Table name should be defined");
    }
    Connection conn = null;
    PreparedStatement ps = null;
    String[] columnNames = conf.get(serdeConstants.LIST_COLUMNS).split(",");

    try {
      initializeDatabaseConnection(conf);
      conn = dbcpDataSource.getConnection();
      ps = conn.prepareStatement(constructQuery(tableName, columnNames));
      return new org.apache.hadoop.mapreduce.lib.db.DBOutputFormat()
              .new DBRecordWriter(conn, ps) {
        @Override
        public void close(TaskAttemptContext context) throws IOException {
          try {
            super.close(context);
          } finally {
            GenericJdbcDatabaseAccessor.this.close();
          }
        }
      };
    } catch (Exception e) {
      cleanupResources(conn, ps, null);
      throw new IOException(e.getMessage());
    }
  }
A data accessor that should in theory work with all JDBC compliant database drivers.
jdbc-handler/src/main/java/org/apache/hive/storage/jdbc/dao/GenericJdbcDatabaseAccessor.java